Angular 是否未定义AfterViewInit?

Angular 是否未定义AfterViewInit?,angular,Angular,您好,我正在使用Angular2网络应用程序,在视图初始化后,我需要触发一个函数,但我得到了错误,我遵循了Angular2官方网站 错误: 异常:未捕获(承诺中):引用错误:未定义ngAfterViewInit ReferenceError:未定义ngAfterViewInit 代码: import { Component } from '@angular/core' ; import { DropDown } from '../services/dropdown'; import

您好,我正在使用Angular2网络应用程序,在视图初始化后,我需要触发一个函数,但我得到了错误,我遵循了Angular2官方网站

错误: 异常:未捕获(承诺中):引用错误:未定义ngAfterViewInit ReferenceError:未定义ngAfterViewInit

代码:

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 ");

                   }

            }
      }
}
});
}//
});

}//您应该从
@angular/core
导入
AfterViewInit
方法:

import { AfterViewInit } from '@angular/core';

您还错过了构造函数结束括号。

您应该从
@angular/core
导入
AfterViewInit
方法:

import { AfterViewInit } from '@angular/core';
而且你还错过了构造函数的结束括号

import { AfterViewInit } from '@angular/core';