【问题标题】:AnguarJs: ng-repeat only work after clicked button inside directiveAngularJs:ng-repeat 仅在指令内单击按钮后才有效
【发布时间】:2017-01-18 03:13:46
【问题描述】:

我想绑定一个数组(customLayers)并将其用于 ng-repeat。 我在 kv.colorMap 对象中填充了数组。 我有三个使用这些技术的指令。但该指令仅在按下该指令内的无功能按钮 (checkResult) 后更新视图上的绑定数组。

指令模板代码:

...
<div class="createInfo colorExprContainer">
    <div ng-repeat="layer in customLayers">{{layer.color}}</div>
</div>

<div class="buttonWrapper text-center">
    <button class="btn" ng-click="checkResult()">Ergebnis prüfen</button>
</div>
...

指令 JavaScript 代码:

app.directive('boolKv', function($parse, $timeout){
return {
    restrict: 'E',
    replace:true,
    scope:true,
    templateUrl: "directives/boolKV/boolKV.html",
    link: function($scope, $element, $attr) {
        ...
        var kv = new BAKV({target: cv[0].id, expr: expr});
        $scope.customLayers = kv.colorMap.layers;
        ...
        $scope.checkResult = function(){console.log("it works!");};
});

有人有想法吗? 非常感谢!

【问题讨论】:

标签: angularjs-directive binding angularjs-ng-repeat ng-repeat


【解决方案1】:

谢谢你 MirMasej!

你是对的,我是在渲染后调用它。也许是因为我使用 EaselJs 库作为画布。单击此画布内的块后,我想获取更新。

我通过添加解决了它,如果有人有更好的想法,我会尝试:

kv.colorMap.onChangedLayer = function(layer) {
      $timeout(function(){
            $scope.$apply();
       });
};

我在更改 colorMap 对象内的数据后调用此 onChangedLayer 事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    相关资源
    最近更新 更多