0
私は学習中にAngularアプリケーションをまとめようとしています。モデルプロパティでデータバインドを使用するのに問題があります。角度のモデルプロパティでデータバインディングが機能しない
Iモデルを有する:のテンプレートに
import { Announcer} from '../models/announcer.model'
....some code omited
announcer: Announcer
loading: Boolean
constructor(private http: Http) { }
ngOnInit() {
this.getRegister(); //I use this code to set the announcer variable
}
getRegister() : void
{
this.loading= true;
this.http.request('http://www.example.com/apiannouncer/show/0').subscribe((res: Response) => {
var result = res.json();
this.announcer= new Announcer(result.name);
this.loading= false;
})
}
:
export class Announcer{
constructor(public name: string){}
}
Iはregister.component.tsでモデルをインポートをannouncer.model.ts register.component.ts私はこれを使用できません:
<div> {{ announcer.name }} </div>
私はこのメッセージが表示されます。
Uncaught (in promise): Error: Error class - inline template:2:5 caused by: self.context.announcer is undefined
controllerAs構文を使用していますか? – Rachmaninoff
私は信じていません。 –
'? '演算子を'