剛開始學習角1.5組件,嘗試一些新的規則,但似乎無法讓我的頭圍繞這一點:Angular 1.5,從ng-repeat外部調用組件函數?
因此,在我主:`
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()。
道歉,如果我沒有得到堆棧溢出格式正確,我幾乎還是一個初學者。
p.s.我讀了類似的問題,但A)在html中沒有任何內容,並且與ng-repeat沒有直接關係
進一步澄清問題(如果需要):運行$ interval的組件如何調用不同的組件重複對象的功能。
你說你想出來的角1.5但在你的腳本標籤有1.2.23。 –
正如我所說,這是由代碼片段程序插入的,我不知道如何正確設置堆棧溢出的格式。 – BaneStar007
我想弄清楚爲什麼你需要調用一個子組件的函數? – Pjetr