1

刚开始学习 Angular 1.5 组件,尝试了一些新规则,但似乎无法理解这一点:

所以在我的主要:`

angular.module('myapp',[])

.controller('appController',['$scope', '$interval',function($scope, $interval) {

    
    $scope.action = function(remote){
      // How do I run obj.action
    };
    
    $scope.objectList = [{name: 1},{name:2},{name:3},{name:4},{name:5}];

    $interval(runList, 1000);
    
    function runList() {
      
      // run Action on objects in objectList? obj.action?
      
      obj.action();
      
    }
}]);

// and in the obj.js file
(function(angular) {
'use strict';


angular.module('myapp').component('obj', {
    template: '<div class="box">{{obj.messsage}}</div>',
    controllerAs: 'obj',
    controller: function() {
    
    var obj = this;
    
    obj.action = function() {
      obj.message = "Updated, therefore Success";
    }
    
    
    },
    bindings: {
        ngModel: '=',
        action: '&'
    }
});
})(window.angular);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-controller="appController">
    <h1>Hello Plunker!</h1>
    
    <obj ng-model="obj" ng-repeat="obj in objectList"></obj>
   
</body>

普朗克

我似乎无法理解,如何在 runList 中从控制器运行组件操作 obj.action()。

抱歉,如果我没有正确设置堆栈溢出格式,我几乎还是个初学者。

ps我读了类似的问题,但是A)在html中没有任何内容,并且与ng-repeat没有直接关系

进一步澄清问题(如果需要):运行 $interval 的组件如何调用不同的组件 ng-repeated 对象的函数。

4

1 回答 1

-1

将 $interval 添加到您的控制器依赖项

于 2016-07-27T08:25:03.807 回答