DevExtreme Angular开发入门:从零开始创建Web应用

发表时间: 2021-07-20 09:39

如果您从头开始创建一个项目,可使用DevExtreme Angular模板,这是一个简单的应用程序,带有导航菜单和响应式布局中的几个示例视图(请参阅实时预览)。

DevExtreme Complete Subscription官方最新版免费下载试用,历史版本下载,在线文档和帮助文件下载-慧都网

您可以使用DevExtreme CLI 生成此应用程序:

npx -p devextreme-cli devextreme new angular-app app-namecd app-namenpm run start

该应用程序已经包含 DataGrid 和 Form UI 组件,可以在src\pages\display-data\
display-data.component.html 和 src\pages\profile\profile.component.html 文件中分别找到它们的配置。以下说明以 Button UI 组件为例展示了如何使用其他
DevExtreme UI 组件:

1. 在将要使用它的 NgModule 中导入DevExtreme UI 组件的模块,打开 src\app\app-routing.module.ts 文件并添加以下代码:

app-routing.module.ts

// ...import { ..., DxButtonModule } from 'devextreme-angular';@NgModule({imports: [ ..., DxButtonModule ],// ...})export class AppModule { }

2. 在标记中配置 DevExtreme UI 组件,将以下代码添加到 src\app\pages\home\home.component.html 文件中:

home.component.html

<!-- ... --><dx-buttontext="Click me"(onClick)="helloWorld()"></dx-button><!-- ... -->

3. 在应用程序类中声明回调函数、事件处理程序和绑定属性。 在这个例子中,我们在 src\app\pages\home\home.component.ts 文件中声明了 onClick 事件处理程序:

home.component.ts

// ...export class AppComponent {helloWorld() {alert('Hello world!');}}

如果您在浏览器中转到主页视图,您应该会看到按钮。