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) 

  }
}

您目前似乎无法做到,因为它似乎没有添加对索引符号的支持。

这已添加到 Angular 2 in this pull request, since issue #16 in Typescript 是 "blocked" 或搁置,直到有对此类运算符的标准化 ES 支持。

本质上,可以在 Angular2 中扩展运算符以支持两者。 属性 语法和索引器语法,但拉取请求似乎没有提供任何迹象表明这是意图,也没有表明目前支持它,特别是当您查看相关测试时。