【问题标题】:AngularJs component Binding is not rendered in templateAngularJs 组件绑定未在模板中呈现
【发布时间】:2018-12-16 20:34:02
【问题描述】:

我有以下组件,

class ModifyServiceController implements ng.IComponentController {
  public value: number;
  public ngModel: ng.INgModelController;
  public a: string;

  public $onInit() {
    window.console.log(this.a);
  }
}

export class ModifyService implements ng.IComponentOptions {
  public controller = ModifyServiceController;
  public template = require('./ModifyService.html');
  public bindings = {
    a: '<',
  };
} 

我有一个模板来显示字符串a..

<div>Value is: {{a}}</div> 

console.log 没有提供任何错误,我得到了显示的值,但在模板中,它没有呈现(我只看到:值是:)。

我在父组件中传递值:

<modify-service a="'blabla'"></modify-service>

我错过了什么吗?我对 AngularJs 完全陌生。

【问题讨论】:

    标签: angularjs angular-components ng-bind


    【解决方案1】:

    组件用默认名称$ctrl实例化它们的控制器:

    <div>Value is: {{$ctrl.a}}</div> 
    

    【讨论】:

    • 谢谢。我习惯 Angular2+ 不需要那种语法。
    猜你喜欢
    • 2016-09-30
    • 2019-04-09
    • 2019-10-27
    • 2020-07-18
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 2017-06-10
    • 2012-01-02
    相关资源
    最近更新 更多