【发布时间】:2023-03-07 18:26:02
【问题描述】:
在 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;
}
在浏览器中出现错误 «Can't bind to 'NgModel' because it is not an known native property » 和 «Can't bind to 'NgIf' because it is '不是已知的原生属性»。
我正在使用 beta 8。
【问题讨论】:
-
同样的错误。也许有进口的东西?
-
我感觉你没有看 angular2 文档谈论绑定语法...angular.io/docs/ts/latest/guide/template-syntax.html