1、@
<div ng-controller="love">
<drink myfaver={{fover}}></drink>
</div>
ar app = angular.module("app",[]);
app.controller("love",["$scope",function($scope){
$scope.fover="百事可乐";
}])
.directive("drink",function(){
return{
restrict:"AE",
scope:{
myfaver:'@'
},
template:"<div>{{myfaver}}</div>"
}
})
2、=
var app=angular.module("app",[]);
app.controller("love",["$scope",function($scope){
$scope.fover="百事可乐";
}])
.directive("drink",function(){
return{
restrict:"AE",
scope:{
myfaver:'='
},
template:"<input type='text' ng-model='myfaver'/>"
}
})
<div ng-controller="love">
控制器:
<input type="text" ng-model="fover" />
指令:
<drink myfaver="fover"></drink>
</div>
var app=angular.module("app",[]);
app.controller("myinput",["$scope",function($scope){
$scope.getName = function(myname){
alert(myname);
}
}])
.directive("setinput",function(){
return{
restrict:"AE",
scope:{
greet:"&"
},
template:"<div><input type='text' ng-model='name' /><button class='btn btn-primary' ng-click='greet({myname:name})'>得到名字</button></div>"
}
})
<div ng-controller="myinput">
<setinput greet="getName(myname)"></setinput>
</div>