9
我想實現的角2的OnInit功能,但我得到以下錯誤在控制檯:Angular2 - OnInit中沒有定義
Error: ReferenceError: OnInit is not defined(...)
有人能指出我在做什麼錯?
這是我的組件:
import { Component, OnInit } from 'angular2/core';
import { ViewEncapsulation } from 'angular2/core';
@Component({
selector: 'Landing',
templateUrl: '/app/views/landing.html',
styleUrls: ['../app/styles/landing.css'],
encapsulation: ViewEncapsulation.None
})
export class LandingComponent implements OnInit {
function checkOverflow() {
var element = document.querySelector('.appContainer');
if((element.offsetHeight < element.scrollHeight) || (element.offsetWidth < element.scrollWidth)){
// your element have overflow
console.log('OVERFLOW!');
}
else{
console.log('NO OVERFLOW');
}
}
OnInit() {
checkOverflow();
}
}