如何在Angular2中将模板绑定表达式作为字符串?

时间:2017-03-22 20:11:37

标签: angular ngmodel binding-expressions

有没有办法在我的组件中获取字符串“myModel”?

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `<input type="text" [(ngModel)]="myModel"/>`
})
export class AppComponent { // how can I access "myModel" here? }

2 个答案:

答案 0 :(得分:0)

只需使用

访问它
this.myModel

并在之前宣布。

myModel:string;

答案 1 :(得分:0)

最近的我可以来到NgModel通过injector.view进入ctor - 但需要根据http://blog.rangle.io/angular-2-ngmodel-and-custom-form-components/进行一些更改,看看我是否能够获得这些表达式。如果有人比我更早得到答案,请在这里发布。感谢名单。

相关问题