已解决----为什么scope.flavor=attrs.flavor; 没有赋值成功?
<!doctype html> <html ng-app="MyModule"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body> <div ng-controller="MyCtrl"> <drink flavor="{{ctrlFlavor}}"></drink> </div> </body> <script src="angular.min.js"></script> <script src="ScopeAt.js"></script> </html>
var myModule = angular.module('MyModule',[]); myModule.controller('MyCtrl',['$scope',function($scope){ $scope.ctrlFlavor="百威"; }]); myModule.directive("drink",function(){ return{ restrict:'AE', template:"<div>{{flavor}}</div>", link:function(scope,element,attrs){ scope.flavor=attrs.flavor; } } });
自己弄漏了一个。。
scope:{
flavor:'@'
}