डोम जोड़तोड़ नियंत्रक, सेवाओं आदि में नहीं होना चाहिए ... लेकिन यह यह निर्देशों ...
केवल एक ही स्थान पर होना चाहिए, अगर आप एक हेरफेर करना चाहते डोम आप के निर्देश का उपयोग करें और वहाँ में अपने हेरफेर करना चाहिए ...
यहाँ AngularJS में डोम जोड़तोड़ के बारे में कुछ अच्छी लेख है ...
Best Practice - Dom Manipulations
DOM Manipulation in AngularJS — Without jQuery
अब के एक निर्देश बनाने की तरह आप चाहते हैं की कोशिश करते हैं। ऐसा लगता है कि आप उन्हें अपनी कक्षा के माध्यम से चुनकर तत्व में हेरफेर करना चाहते हैं। ठीक है कोई समस्या नहीं तो हम (सब कुछ दिखाने के लिए वर्बोज़ संस्करण) एक निर्देश जो restrict:'C'
मतलब है कक्षा है ...
यहाँ
हमारे निर्देश घोषणा है ... बनाने के लिए
app.directive('myClass',function(){
// Runs during compile
return {
// name: '',
// priority: 1,
// terminal: true,
// scope: {}, // {} = isolate, true = child, false/undefined = no change
// controller: function($scope, $element, $attrs, $transclude) {},
// require: 'ngModel', // Array = multiple requires, ? = optional,^= check parent elements
restrict: 'C', // E = Element, A = Attribute, C = Class, M = Comment
// template: '',
// templateUrl: '',
// replace: true,
// transclude: true,
// compile: function(tElement, tAttrs, function transclude(function(scope, cloneLinkingFn){ return function linking(scope, elm, attrs){}})),
link: function($scope, iElm, iAttrs, controller) {
console.log('Here is your element', iElm);
// DO SOMETHING
}
};
});
यहाँ PLUNKER है की जरूरत है। .. $('selector')
के लिए
आप [? __How मैं "AngularJS में लगता है कि" कि मेरा कोई jQuery पृष्ठभूमि है __] के माध्यम से जाना चाहिए (http://stackoverflow.com/questions/14994391/how- do-i-think-in-angularjs-if-i-have-a-jquery-background) पहले। – Satpal