我在Angular2中渲染表达式时遇到了麻烦.
例如,我有类似下面的例子,但{{profile.name}}什么都没有.
然而,它不仅仅是在从组件实例访问某些东西时.无论我放在表达式中,它都不会呈现(例如{{1 + 2}}).更奇怪的是,它删除了包含表达式的DOM元素的所有内容.
import { Component, View } from 'angular2/core'
@Component({
selector: 'my-component'
})
@View({
template: `
<div class="user">
{{profile.name}}
</div>
`
})
export class MyComponent {
profile
constructor() {
this.profile = {
name: 'John Smith'
}
}
}
Run Code Online (Sandbox Code Playgroud)
不知道我错过了什么.任何帮助将非常感激!
编辑
所以我做了一些进一步的测试,发现问题只发生在我使用的时候<router-outlet>.所以我有一些看起来像这样的东西(代码量的道歉)
app.ts
import { View, Component } from 'angular2/core'
import { RouteConfig, RouterOutlet } from 'angular2/router'
import { Home } from './home'
@Component({
selector: 'my-app'
})
@View({
template: '<router-outlet></router-outlet>',
directives: [RouterOutlet] …Run Code Online (Sandbox Code Playgroud)