angular2 中具有连字符属性的 Elvis 运算符
Elvis operator with hyphenated properties in angular2
在 angular2 模板中访问带连字符的属性时如何使用 elvis 运算符
http://plnkr.co/edit/z3Wqn7EScgxcAhrFJWjv?p=preview
//our root app component
import {Component} from 'angular2/core'
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>Hello {{name}}</h2>
{{asyncObj1?.theprop}}
{{asyncObj2?['the-prop']}} <!-- this throws error -->
</div>
`,
directives: []
})
export class App {
constructor() {
setTimeout(function(){
this.asyncObj1 = {
'theprop': 'value'
}
this.asyncObj2 = {
'the-prop': 'async value'
}
}, 2000)
}
}
在 angular2 模板中访问带连字符的属性时如何使用 elvis 运算符
http://plnkr.co/edit/z3Wqn7EScgxcAhrFJWjv?p=preview
//our root app component
import {Component} from 'angular2/core'
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>Hello {{name}}</h2>
{{asyncObj1?.theprop}}
{{asyncObj2?['the-prop']}} <!-- this throws error -->
</div>
`,
directives: []
})
export class App {
constructor() {
setTimeout(function(){
this.asyncObj1 = {
'theprop': 'value'
}
this.asyncObj2 = {
'the-prop': 'async value'
}
}, 2000)
}
}