anglejs – 角2,组件内部主要组件
发布时间:2020-12-17 08:22:04 所属栏目:安全 来源:网络整理
导读:我已经用角度2演示了。 现在我想创建一个新的组件,并在我的应用程序中使用它。 我当前的应用程序: import {Component,Template,bootstrap} from 'angular2/angular2';import {UsersComponent} from './components/users/component.js';// Annotation secti
我已经用角度2演示了。
现在我想创建一个新的组件,并在我的应用程序中使用它。 我当前的应用程序: import {Component,Template,bootstrap} from 'angular2/angular2'; import {UsersComponent} from './components/users/component.js'; // Annotation section @Component({ selector: 'my-app' }) @Template({ url:"app.html" }) // Component controller class MyAppComponent { newName:string; names:Array<string>; constructor() { this.name = 'Florian'; } showAlert(){ alert("It works"); } addName(){ names.push(newName); newName = ""; } } bootstrap(MyAppComponent); 我的组件: import {Component,bootstrap} from 'angular2/angular2'; // Annotation section @Component({ selector: 'users' }) @Template({ url:"./template.html" }) // Component controller class UsersComponent { newName:string; names:Array<string>; constructor() { } addName(){ names.push(newName); newName = ""; } } 我不知道我的用户组件的语法是否正确。 我的应用模板: <h1>Hello {{ name }}</h1> <h2>{{2+2}}</h2> <hr /> <button (click)="showAlert()">Click to alert</button> <users></users> 那么如何连接用户组件? 我在控制台中收到的错误: "Error loading "components/users/component.js" at <unknown>?Error loading "components/users/component.js" from "app" at http://localhost:8080/app.es6?Cannot read property 'replace' of undefined"
角度日历演示有两个嵌套组件(日历和日历单元格)
https://github.com/djsmith42/angular2_calendar.git。从我可以看到,您的MyAppComponent应该从@ Template的指令列表中引用Users组件,如下所示:
@Template({ url: System.baseURL+'app/components/calendar/calendar.html',directives: [ Foreach,If,CalendarCell ] }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |