I\'m just starting with angularjs, and am working on converting a few old JQuery plugins to Angular directives. I\'d like to define a set of default options for my (element)
Use the =?
flag for the property in the scope block of the directive.
angular.module('myApp',[])
.directive('myDirective', function(){
return {
template: 'hello {{name}}',
scope: {
// use the =? to denote the property as optional
name: '=?'
},
controller: function($scope){
// check if it was defined. If not - set a default
$scope.name = angular.isDefined($scope.name) ? $scope.name : 'default name';
}
}
});