我有一个像这样设置的角度应用程序
<div ng-controller"FooCtrl">
<bar></bar>
</div>
使用脚本
app.controller('FooCtrl', ['$scope', function($scope) {
$scope.fn = function() { window.alert("Hello World"); }
}]);
app.directive('bar', function() {
return {
restrict: 'AE',
templateUrl: "/bar.html",
};
});
并且bar.html部分模板为
<button ng-click="fn();">Exec</button>
但点击该按钮不起作用。
我尝试添加
...
transclude:true
...
指令返回,但这没有成功。
如何在指令中启用对控制器功能的访问?
答案 0 :(得分:2)