Hello,
I would like to add ng-controller='somecontrollername' dynamically
depending on it's parent scope user role value.
The snippet I tried to implement is below,
<div dynamic-controller class="pull-right">
<button type="submit" class="btn" ><span class="glyphicon
glyphicon-remove"></span> *Cancel*</button>
<button type="submit" class="btn btn-primary active"
ng-click="replyToMessage()"><span class="glyphicon glyphicon-ok"></span> *Send
Reply*</button></div>
angular.module('Messaging')
.directive('dynamicController', function ($compile) {
return {
restrict: 'A',
replace: true,
priority: 1000,
compile: function compile(element, attrs) {
debugger;
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
debugger;
//Deciding which controller attribute to add.
if (scope.$parent.user.role !== '20') {
element.attr('ng-controller', 'CHSMessagingCtrl');
} else {
element.attr('ng-controller', 'MessagingCtrl');
}
$compile(iElement)(scope);
},
post: function postLink(scope, iElement, iAttrs,
controller) {
}
};
}
};
});
I am new to Angularjs. It will be helpful if someone corrects me on this.
Thanks,
Krishna
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.