UI组件库Kendo UI for Angular入门指南教程

摘要:
ConversationalUI包提供了KendoUI聊天组件,该组件允许用户参与与其他用户或聊天机器人的聊天会话。ConversationalUIPackage是KendoUIforAngular的一部分,这是一个专业级UI库,具有100多个组件,用于构建现代且功能丰富的应用程序。KendoUIforAngular最新版工具下载基本用法以下示例演示了Chat的实际操作。使用AngularCLI进行快速设置AngularCLI支持通过ngadd命令添加包,该命令一步执行一组其他单独需要的命令。ngadd@progress/kendo-angular-conversational-ui手动设置1.下载并安装包及其对等依赖项。npminstall--save@progress/kendo-angular-conversational-ui@progress/kendo-angular-common@progress/kendo-angular-buttons@progress/kendo-angular-popup@progress/kendo-licensing2.安装后,在您的应用程序根

Conversational UI组件弥合了Web 和下一代自然语言应用程序之间的差距。Conversational UI 包提供Kendo UI聊天组件,该组件允许用户参与与其他用户或聊天机器人的聊天会话。

Conversational UI Package 是Kendo UI for Angular的一部分,这是一个专业级 UI 库,具有 100 多个组件,用于构建现代且功能丰富的应用程序。

Kendo UI for Angular最新版工具下载

基本用法

以下示例演示了 Chat 的实际操作。

app.component.ts

import { Component } from '@angular/core';

import { Subject, from, merge, Observable } from 'rxjs';
import { switchMap, map, windowCount, scan, take, tap } from 'rxjs/operators';

import { ChatModule, Message, User, Action, ExecuteActionEvent, SendMessageEvent } from '@progress/kendo-angular-conversational-ui';
import { ChatService } from './chat.service';

@Component({
providers: [ ChatService ],
selector: 'my-app',
template: `
<kendo-chat
[messages]="feed | async"
[user]="user"
(sendMessage)="sendMessage($event)"
>
</kendo-chat>
`
})
export class AppComponent {
public feed: Observable<Message[]>;

public readonly user: User = {
id: 1
};

public readonly bot: User = {
id: 0
};

private local: Subject<Message> = new Subject<Message>();

constructor(private svc: ChatService) {
const hello: Message = {
author: this.bot,
suggestedActions: [{
type: 'reply',
value: 'Neat!'
}, {
type: 'reply',
value: 'Thanks, but this is boring.'
}],
timestamp: new Date(),
text: 'Hello, this is a demo bot. I don`t do much, but I can count symbols!'
};

// Merge local and remote messages into a single stream
this.feed = merge(
from([ hello ]),
this.local,
this.svc.responses.pipe(
map((response): Message => ({
author: this.bot,
text: response
})
))
).pipe(
// ... and emit an array of all messages
scan((acc: Message[], x: Message) => [...acc, x], [])
);
}

public sendMessage(e: SendMessageEvent): void {
this.local.next(e.message);

this.local.next({
author: this.bot,
typing: true
});

this.svc.submit(e.message.text);
}
}

chat.service.ts

import { Observable, Subject } from 'rxjs';
import { Injectable } from '@angular/core';

// Mock remote service

@Injectable()
export class ChatService {
public readonly responses: Subject<string> = new Subject<string>();

public submit(question: string): void {
const length = question.length;
const answer = `"${question}" contains exactly ${length} symbols.`;

setTimeout(
() => this.responses.next(answer),
1000
);
}
}

app.module.ts

import { NgModule } from '@angular/core';
import { Component } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ChatModule } from '@progress/kendo-angular-conversational-ui';

import { AppComponent } from './app.component';

@NgModule({
imports: [ BrowserModule, BrowserAnimationsModule, ChatModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})

export class AppModule { }

main.ts

import './polyfills';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
安装

使用快速设置 (Angular CLI) 或手动添加包。

使用Angular CLI进行快速设置

Angular CLI 支持通过 ng add 命令添加包,该命令一步执行一组其他单独需要的命令。

ng add @progress/kendo-angular-conversational-ui

手动设置

1. 下载并安装包及其对等依赖项。

npm install --save @progress/kendo-angular-conversational-ui @progress/kendo-angular-common @progress/kendo-angular-buttons @progress/kendo-angular-popup @progress/kendo-licensing

2. 安装后,在您的应用程序根或功能模块中导入 ChatModule。

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChatModule } from '@progress/kendo-angular-conversational-ui';
import { AppComponent } from './app.component';

@NgModule({
bootstrap: [ AppComponent ],
declarations: [ AppComponent ],
imports: [
BrowserModule,
BrowserAnimationsModule,
ChatModule
]
})
export class AppModule {
}

3. 您需要安装一个Kendo UI主题来设置组件的样式。

4. 对于Angular 9.x 及更高版本,安装 @angular/localize 包:

  1. 运行npm install --save @angular/localize。
  2. 添加import '@angular/localize/init';到你的src/polyfills.ts文件。

5. 按照 Kendo UI for Angular My License 页面上的说明激活您的授权许可。 如果您的应用程序已包含 Kendo UI 许可文件,则可以跳过此步骤。

依赖关系

Conversational UI 包需要您的应用程序必须安装以下对等依赖项:

  • @angular/common
  • @angular/core
  • @progress/kendo-angular-buttons
  • @progress/kendo-angular-popup
  • @progress/kendo-licensing
  • rxjs 5.5+

Kendo UI for Angular | 下载试用

Kendo UI for Angular是Kendo UI系列商业产品的最新产品。Kendo UI for Angular是专用于Angular开发的专业级Angular组件。telerik致力于提供纯粹的高性能Angular UI组件,无需任何jQuery依赖关系。


了解最新Kendo UI最新资讯,请关注Telerik中文网!

免责声明:文章转载自《UI组件库Kendo UI for Angular入门指南教程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CS231N 数据预处理(data proprecessing)python嵌入C++ boost.python如何在C++中调用含有不定长参数tuple变量和关键字参数dict变量的函数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

angularjs-双向数据绑定之输入框信息随时显示

以下为angularjs 双向数据绑定用处之一:用户输入框输入信息,随着用户信息的输入,信息随时显示在某元素中 双向数据绑定如果不需要对输入数据有任何操作,只是把用户输入的信息显示在页面中,则不需要对<div ng-app=''>里面写任何任内,只需要谢伟空字符即可;一个为用户输入信息元素绑定ng-model='起的名字',显示元素为绑定方式为...

小程序开发笔记(六)--使用七牛云上传图片

选取相册及本地预览 选择手机相册 preUpload() { let that = this; // let imglist=[]; wx.chooseImage({ count: 9, //最多可以选择的图片张数 sizeType: ["original", "compressed"],...

angular写的一个导航栏

ts import { Component } from '@angular/core'; // 定义一个interface interface Menu{ title:string,link:string,id:string } @Component({ selector: 'app-root', templateUrl: './app.co...

Angular:ViewProviders和Providers的区别

在Angular中使用依赖注入(DI)的时候,我们一般会使用providers。其实要做同样的事我们还有另外一个选择:viewProviders。viewProviders允许我们定义只对组件的view可见的provider。下面我们用例子详细的说明这一点。 假设我们有一个简单的服务: // myService.service.ts import { In...

angular 路由传参的三种方式

1. 问号后面带的参数 url:http://localhost:4200/news?key=japan html 调用方法: <a[routerLink]="['/news']"[queryParams]="{key:'japan'}"> 跳转 </a> ts 调用方法: // 构造函数传入 privaterouter:Rou...

移动前端—H5实现图片先压缩再上传

  在做移动端图片上传的时候,用户传的都是手机本地图片,而本地图片一般都相对比较大,拿iphone6来说,平时拍很多图片都是一两M的,如果直接这样上传,那图片就太大了,如果用户用的是移动流量,完全把图片上传显然不是一个好办法。   目前来说,HTML5的各种新API都在移动端的webkit上得到了较好的实现。根据查看caniuse,本demo里使用到的Fi...