我试图启动一个有角度的项目,我创建了一个简单的组件并启动了console.log,但是我遇到了令人困惑的问题。当我从ts文件调用html文件中的函数时,它运行两次
TS:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.less']
})
export class HelloComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
log(val)
{
console.log(val);
}
test() {
let time = new Date()
console.log(time.getSeconds());
}
}
html:
你好!
{{log('test')}} {{test()}}
答案 0 :(得分:0)
您在何处以及多久调用一次组件? 您能在stackblitz上产生一个简单的例子吗?
没有任何更多信息,我们只能猜测它是什么。 您可能已经通过''两次调用了组件。
每个实例将调用您的所有模板,从而调用其模板函数。