【发布时间】:2016-09-12 10:27:01
【问题描述】:
我正在尝试实现 angular 2 onInit 函数,但在控制台中出现以下错误:
错误:ReferenceError:未定义 OnInit(...)
谁能指出我做错了什么?
这是我的组件:
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();
}
}
【问题讨论】:
标签: typescript angular