Just started learning Angular 1.5 components, Trying out some of new rules, but can't seem to get my head around this:
So in my Main:`
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>
I just can't seem to get it through my head, how to run the components action obj.action() from the controller, in runList.
Apologies if I'm not getting stack-overflow formatting right, I'm pretty much still a beginner.
p.s. I read the similar question, but A) had nothing in the html, and wasn't directly related to ng-repeat
further Clarification of question (if needed): how could a component which runs the $interval call different components ng-repeated object's function.