javascript - Angular JS isolated scope not working on directives with service calls -


i developing directive content changes based on attribute. if having more 1 directive in page, isolated scope not working, 2 directives having same values. happening when there service calls in directives , isolated scope works when there no services , promises.

directive

.directive('ex', function() { return {     restrict: 'e',     scope: {},     template: '<div>test{{test}}</dic>',     link: function(scope, elem, attr) {         if(attr.label == 'dir1') {             scope.test = 'directive 1';         }         if(attr.label == 'dir2') {             scope.test = 'directive 2';         }     } } }) 

and html

<ex label="directive1"></ex> <ex label="directive2"></ex> 

output

directive 1 directive 2 

this works perfectly, when having http service call in directive , if scope value depends on it, getting wrong output like

directive 1 directive 1

please me find out why isolated scope not working while using service calls in directive.

any appreciated. thanks

edit

directive code $http

.directive('ex', ['service', function(service) { return {     restrict: 'e',     scope: {},     template: '<div>test{{test}}</dic>',     link: function(scope, elem, attr) {         service.getdata(attr.label).then(function(response) {           if(response.data.value == 'testing') {             scope.test = 'directive 1';           } else {             scope.test = 'directive 2';           }         })      } } }]) 


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -