I am trying to create a directive that has an optional "label" for a button - if this label is not supplied, I want it to have a default value
this is the directive
angular.module('myApp')
.directive('myButton',function(){
var ctrl = function ($scope) {
var controller = this;
controller.label = controller.label || 'Save';
console.log("label=",controller.label);
};
return {
replace: true,
restrict: 'E',
scope: {
label: '@?',
},
templateUrl: 'directives/myButton.html',
controller: ctrl,
controllerAs: 'controller',
bindToController: true,
};
});
the html in the template is this
<md-toolbar>
<div class="md-toolbar-tools">
<span flex></span>
<md-button class="md-raised">{{controller.label}}</md-button>
</div>
</md-toolbar>
and I am calling the directive like this
<my-button label="fooBar"></my-button>
this works - and I see the label "fooBar" on the button, and 'label=fooBar' on the console
however, if I don't supply the label
<my-button></my-button>
The button has no label, but I see 'label=Save' on the console
what am I missing ?
thanks