こんにちは、私は私が機能を起動する必要があるビュー初期化した後、Angular2のWebアプリで働いています。しかし、私はエラーを得た、私は公式angular2サイトhttps://angular.io/docs/ts/latest/api/core/index/AfterContentInit-class.htmlに従っているAfterViewInitが定義されていませんか?
エラー: 例外:(約束で)キャッチされません: ReferenceError:ngAfterViewInitは にReferenceErrorが定義されていません。
import { Component } from '@angular/core' ;
import { DropDown } from '../services/dropdown';
import {ExponentialStrengthPipe} from '../exponential-strength.pipe';
import {HashLocationStrategy, Location, LocationStrategy} from '@angular/common';
@Component({
selector:'pageone',
templateUrl:'app/page1/page1.component.html',
providers:[DropDown,Location, {provide: LocationStrategy, useClass: HashLocationStrategy}]
})
export class Page1Component implements AfterViewInit
{
ind:number=1.5;
usa:number=1.5;
myd:any;
search:string;
mydetails:any;
constructor(private mydata:DropDown,location: Location){
this.myd = mydata.getData();
this.mydata.getMyprofile().subscribe(posts=>{
console.log(posts);
this.mydetails=posts;
});
ngAfterViewInit() {
// ...
}
}
addLocation(){
if(this.search=="" || this.search==undefined)
{
alert("Please enter loction");
}
else
{
for(var i=0;i<this.myd.length;i++)
{ var count=0;
if(this.myd[i].locationName==this.search)
{
alert("Already Present")
count=1;
}
}
if(count==0)
{
var id = this.myd.length+1;
this.myd.push({id:id,locationName:this.search});
alert(this.search+" Has Been Added ");
}
}
}
}
:ngAfterViewInitは
コードを定義されていません。
機能は、あなたが@angular/core
からAfterViewInit
方法をインポートする必要があり
ngAfterViewInit() {
// ...
}
コンストラクタの外で定義する必要があります... – Gopinath