ऐसा करने के दो तरीके हैं:
1 एनजी-init
function controller($scope) {
$scope.items = [{id: 1, name: 'one'}, {id: 2, name: 'two'}];
$scope.initRepeaterItem(index, item) {
console.log('new repeater item at index '+index+':', item);
}
}
<ul>
<li ng-repeat="item in items" ng-init="initRepeaterItem($index, item)"></li>
</ul>
2 MutationObserverथोड़ा और अधिक जटिल
एक निर्देश के अंदर यह करें , उस तत्व पर जिसके माता-पिता को नया बच्चा मिल जाता है एन (<ul>
इस मामले में)
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// you get notified about DOM mutations here
// check mutation.type if it was an insertion
console.log(mutation.target.nodeName, mutation.type, mutation);
});
});
var config = {childList: true, attributes: false, characterData: false,
subtree: false, attributeOldValue: false, characterDataOldValue: false};
observer.observe(element[0], config);
Demo http://plnkr.co/h6kTtq
Documentation https://developer.mozilla.org/en/docs/Web/API/MutationObserver
Browser support http://caniuse.com/mutationobserver
नियंत्रक में डोम हेरफेर के बारे में, यह [यहाँ कहते हैं] (https://groups.google.com/forum/?fromgroups=#!topic/angular/ u52B5bVzdqs) कि आपको यह बिल्कुल नहीं करना चाहिए। इसे निर्देश में जाना चाहिए। यह क्यों काम नहीं करता है, मुझे नहीं पता, लेकिन शायद यह इसलिए है क्योंकि इस बिंदु पर कोणीय अभी भी अपनी सामग्री चला रहा है। – Narretz
मुझे लगता है कि यदि आप नए डोमेन तत्व तक पहुंचने का प्रयास कर रहे हैं या क्यों कारण के कारण आप बेहतर समाधान प्राप्त कर पाएंगे। यदि आप समझा सकते हैं कि आपको शायद आपकी समस्या को कोणीय तरीके से हल करने का उत्तर मिलेगा। – ganaraj