1. create a service, which can be initialised from a node
var app = angular.module("myApp", [dependencies]);
2. app exists, create a controller, controlling a node and its children
app.controller("nameCtrl", function($scope){ //xxxCtrl is naming convention
//$scope can have function and attributes in json favor
$scope.content = {message:"I am content"}
$scope.foo=function(){...}
})
3. app, controler exist, directive is customised node/attribute
app.directive("name",function(){
return {
restrict: "E || A || M",
$scope{
element/attr : "@ || & || = ", // @attr, &attr, =attr
}, //isolated scope, used in multiple instances of the directive
template: 'Here is returned inner html, can do {{bindModule or value}}
',
link:function(scope,element,attrs,[depended controller])
{...} //like the constructor
controller: function() {
foo1 = function(){}
} // an API controller that other directive will depend on
}
})
app.directive("anotherName", function(){
require : 'name'
link: function(scope,element,attrs, nameCtrl){...can invoke nameCtrl foo1} //nameCtrl - naming convention
})
没有评论:
发表评论