【发布时间】:2014-10-15 10:46:42
【问题描述】:
我有以下问题。我想从具有隔离范围的指令中调用控制器函数。
HTML:
<div ng-controller="MainController">
<test></test>
</div>
JS:
var app = angular.module("app", []);
app.controller("MainController", function ($scope) {
$scope.testFunction = function () {
console.log("You just call testFunction()!");
};
});
app.directive("test", function () {
return {
restrict: "E",
scope: {},
template: "<h1 ng-click='testFunction()'>Hello world!</h1>"
};
});
当指令没有独立作用域时,调用函数跟随。
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-scope