I recently came across this directive in AngularJS:
productApp.directive('notification', function($timeout) {
return {
restrict : 'E',
replace : true,
scope : {
type: "@",
message: "@"
},
template : '<alert class="alert alert-type">message</alert>',
link : function(scope, element, attrs) {
$timeout(function() {
element.hide();
}, 3000);
}
}
});
This allows me to call it from the view like so:
<notification type="alert.type" message="alert.msg"></notification>
In my controller, I have the alert object defined as follows:
$scope.alert = { type : 'success', msg : 'This is a test'};
I was wondering how I can pass the type dynamically. I tried doing that, but it didn't seem to work. When I pass "alert-success" to the directive, it works fine, but I want it to be dynamic. Is there a way to achieve this?
Thank you.