Angular 01 - Module Constant examples
HTML
<div data-ng-app="App1">
<div data-ng-controller="SomeParentCtrl">
<div data-ng-controller="SomeCtrl">
<b>Scalar Binding:</b><br/>
<div>Number:<span data-ng-bind="someNumber"/></div>
<div>Text:<span data-ng-bind="someText"/></div>
<!-- to object properties -->
<div>First:<input data-ng-model="someObject.first"/></div>
<!-- to behaviour -->
<div>Last:<span data-ng-bind="someObject.full()"/></div>
<button type="button">{{buttonName}}</button>
<button type="button">Save</button>
<button type="button">Save</button>
</div>
</div>
</div>
JavaScript
var app1 = angular.module('App1', []);
//ABOUT:
//Constants are exactly the same as values, in that they
//are key/value (of any type) that are defined at the module
//level, that then can be DI'ed into other components (controllers, etc.)
//note how '$scope' is mapped to $sc: and 'foo' is DI'ed value:
app1.controller('SomeParentCtrl', ['$scope', 'foo', function ($sc, foo) {
$sc.someText = foo;
}]);
app1.controller('SomeCtrl', ['$scope', 'bar', function ($scope, bar) {
$scope.someNumber = bar.number;
$scope.someObject = {
first : 'John',
last : 'Smith',
full : function(){return this.first + ' ' + this.last;}
};
$scope.data= bar.buttonName;
}]);
//NOTICE:
//Define a value, that will be injected into the controllers:
//Note that it works even if defined later, as long as it is defined
//before controller is constructed:
app1.constant("foo", "fooey");
app1.constant("bar",{
"number":15,
"buttonName":"Save"});