Wie elvis Operator verwenden, wenn hyphenated Eigenschaften in angular2 Vorlagen Zugriff aufElvis-Operator mit Bindestrichen Eigenschaften in angular2
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)
}
}
Sie würden eine ngIf benötigen. Etwas wie '
oder ' {{asyncObj2 ['the-prop']}}', das würde kein zusätzliches Markup ie- 'div wrapper' hinterlassen. –