0

有没有办法在我的组件中获取字符串“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? }
4

2 回答 2

0

只需访问它

this.myModel

并在之前声明。

myModel:string;
于 2017-03-22T20:16:26.093 回答
0

最接近 NgModel 的我是通过 injector.view 在 ctor 中 - 但需要根据http://blog.rangle.io/angular-2-ngmodel-and-custom-form-components/进行一些更改才能看到如果我能得到这些表达。如果有人比我早得到答案,请在此处发布。谢谢。

于 2017-12-11T20:27:05.037 回答