我正在尝试从我的内部text/ng-template
脚本标签中应用 html。但它无法正常工作。如何html
从script
标签申请?
这是我的代码和html:
js部分:
//our root app component
import {Component} from 'angular2/core'
@Component({
selector: 'my-app',
providers: [],
templateUrl: "template.html", //this is the id.
directives: []
})
export class App {
public title = "My Title";
private userName = "Test Name";
constructor() {
this.name = 'Angular2'
}
}
HTML部分:
<body>
<my-app>loading...</my-app>
//template declared
<script type="text/ng-template" id="template.html">
<h2>{{title}}</h2>
<div>
<h2>Hello {{name}}</h2>
<h2>{{userName}}</h2>
</div>
</script>
</body>
我收到一个错误:
未能加载 template.html
正确的使用方法是什么?