.directive('dateRange', [
function () {
return {
scope:{},
restrict: 'A',
controller: 'dateRangeController',
templateUrl: "daterange.tpl.html",
link: function (scope, element) {
var container = element;
scope.dosmth = function () {
...
};
}
};
}
]);
<span ng-click="dosmth()">
我只需要访问dosmth()函数中的范围和容器。我知道这是可能的。但我无法理解为什么在这种情况下不起作用。
答案 0 :(得分:0)
在您创建的隔离范围指令中,范围没有从父级继承的任何内容,因为声明为空scope:{}
。声明变量或函数,如下所示。
scope: {
varOne:'@',
vartwo:'=',
methodone:'&'
}
或从指令定义中删除scope:{}
。