获取双向数据绑定的数据

Getting data for two way data binding

本文关键字:数据 数据绑定 获取      更新时间:2023-09-26

为什么我无法访问onclick方法中定义的方法中的数据?

onclick: function(d, i) {
  $scope.country = d.name;
  console.log($scope.country);
}

我想从对象中获取名称并以 HTML <h1>Clicked: {{country}}</h1> 普伦克

国家/地区项目指令内部定义了隔离的范围。因此,您需要在html中将其传递国家/地区:

<country-item country="country"></country-item>

如果需要在单击图表条时添加相同的行为,则必须在 onClick 回调中添加 $scope.$apply():

onclick: function(d, i) {
    $scope.country = d.name;
    $scope.$apply();
}

摘要周期已经结束,您需要通知 Angular 某些内容已更改。