:
app.directive('myButton', function($timeout) {
var tpl = function(scope, element, attrs) {
var btn = "<button ng-if='trigger'>"
+ "a<ng-transclude></ng-transclude>"
+ "</button>"
+ "<button ng-if='!trigger'>"
+ " <ng-transclude></ng-transclude>"
+ "</button>";
return btn;
}
return {
restrict: 'E',
template: tpl,
transclude:true,
scope: {
eventData: '=',
trigger: '=triggerEventIf'
},
link: function(scope, element, attrs, ctrl, transclude) {
scope.event = {
'title': scope.eventData.title
}
var setAttributes = function(){
for(var attribute in attrs){
if(attribute !== 'triggerEventIf' && attribute.charAt(0) !== '$')
angular.element(element[0].children).attr(attribute,attrs[attribute])
}
}
scope.$watch('trigger', function(oldValue, newValue){
if(oldValue !== newValue){
$timeout(function(){
setAttributes();
});
}
})
$timeout(function(){
setAttributes();
});
}
};
});
http://plnkr.co/edit/Hk1AvRS3nN4YXqcLvZGR?p=preview
.
, $timeout, , setAttributes() angular. setAttributes DOM , , angular, . $timeout - angular -. , , . angular , $timeout . , , .
$apply $digest , . $timeout.
, .