What you are trying to do is control the attribute property in the directive. You can view the attribute change property with $ observ () as follows:
angular.module('myApp').directive('conversation', function() { return { restrict: 'E', replace: true, compile: function(tElement, attr) { attr.$observe('typeId', function(data) { console.log("Updated data ", data); }, true); } }; });
Keep in mind that I used the compilation function in the directive here because you did not mention if you have any models and whether it depends on performance.
If you have models, you need to change the compilation function to a โlinkโ or use the โcontrollerโ and control the property of model changes, you should use $ watch () , and take the brackets from the property from angular {{}}, for example:
<conversation style="height:300px" type="convo" type-id="some_prop"></conversation>
And in the directive:
angular.module('myApp').directive('conversation', function() { return { scope: { typeId: '=', }, link: function(scope, elm, attr) { scope.$watch('typeId', function(newValue, oldValue) { if (newValue !== oldValue) {
j8io Dec 31 '14 at 12:07 2013-12-31 12:07
source share