【问题标题】:Two way databinding in Angular when using method in template在模板中使用方法时,Angular 中的两种方式数据绑定
【发布时间】:2014-11-30 14:03:15
【问题描述】:

有没有办法告诉 Angular $scope 中的特定函数依赖于 $scope 中的某些其他字段?我想在数据模型中隐藏一些功能,例如:

$scope.user = {
   name: "John",
   surname: "Smith",
   getUsername: function() {
      return [this.name, this.surname].join(' ');
   }
}

然后我想在html模板中使用$scope.user.getUsername(),但是当我更改$scope.user.name时,模板不会刷新。有一种方法可以告诉 Angular 这个函数依赖于其他字段吗?

【问题讨论】:

    标签: javascript angularjs data-binding angularjs-scope


    【解决方案1】:

    好的,事实证明 Angular 是自动完成的,但我在不使用 $apply 的情况下更改了它。

    【讨论】:

      猜你喜欢
      • 2014-02-25
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 2020-09-01
      • 2019-06-27
      相关资源
      最近更新 更多