<分区>
在 Angular 2 组件中我有 authbox.component.ts
import {Component} from 'angular2/core';
import {COMMON_DIRECTIVES} from 'angular2/common';
import {Credentials} from './credentials'
@Component({
selector: 'authbox',
template: `<div>
<div class="login-panel" *NgIf="!IsLogged">
<input type="text" *NgModel="credentials.name" />
<input type="password" *NgModel="credentials.password" />
<button type="button" (click)="signIn(credentials)">→| Sign In</button>
</div>
<div class="logged-panel" *NgIf="IsLogged">
<span>{nickname}</span> <button type="button" (click)="signOut()">|→ Sign out</button>
</div>
</div>`,
directives: [COMMON_DIRECTIVES]
})
export class AuthBoxComponent {
private _isLogged: boolean;
get IsLogged(): boolean {
return this._isLogged
}
set IsLogged(value: boolean) {
this._isLogged = value;
}
public credentials: Credentials;
}
在浏览器中我得到错误«无法绑定(bind)到'NgModel',因为它不是已知的原生属性»和«无法绑定(bind)到'NgIf',因为它是'一个已知的本土属性(property)»。
我正在使用测试版 8。