传递一个函数引用2级深度,不在angularjs中工作
我有一个祖父母指令,父母指令和孩子指令如下 祖父母组件有一个函数,比如说传递一个函数引用2级深度,不在angularjs中工作,angularjs,typescript,Angularjs,Typescript,我有一个祖父母指令,父母指令和孩子指令如下 祖父母组件有一个函数,比如说func(),我想在子组件中执行该函数 调用父指令的父级模板中的HTML <div ... on-item-drop="func()"></div> 传递给父控制器 家长控制器 function parentDirective(): ng.IDirective { return { templateUrl($elem, $attr) {
func()
,我想在子组件中执行该函数
调用父指令的父级模板中的HTML
<div ... on-item-drop="func()"></div>
传递给父控制器
家长控制器
function parentDirective(): ng.IDirective {
return {
templateUrl($elem, $attr) {
...
},
scope: {
...
OnDropExpr: "&onItemDrop" <<<------ passing down the function expression,
able to use this perfectly in parent component but not in child
},
}
function childDirective(): ng.IDirective {
return {
templateUrl($elem, $attr) {
...
},
scope: {
...
OnSelectExpr: "&onSelectExpr" <-- passing down the function expression
},
link($scope: any, elem, attr, $ctrl: any[]) {
$scope.$on('dragnDropSelected', function(evt,data) {
if (attr.onSelectExpr) {
$scope.OnSelectExpr({ ... }); <<<------ this is not working
}
});
},
}
angular.module("...", ...)
.controller("listCtrl", ListController)
.directive("listControl", listControlDirective());
function parentDirective():ng.IDirective{
返回{
模板URL($elem,$attr){
...
},
范围:{
...
OnDropExpr:“&onItemDrop”在我将子控制器中的&onSelectExpr
更改为=onSelectExpr
后,函数开始执行
它起作用的原因是,当我们使用&
时,它是在父作用域中执行的,而不是在应该执行它的父作用域中。作用域设置和使用之间的大小写不同…onSelectExpr
vsonSelectExpr
@charlietfl很抱歉,键入问题时出错,它是我不工作了
function childDirective(): ng.IDirective {
return {
templateUrl($elem, $attr) {
...
},
scope: {
...
OnSelectExpr: "&onSelectExpr" <-- passing down the function expression
},
link($scope: any, elem, attr, $ctrl: any[]) {
$scope.$on('dragnDropSelected', function(evt,data) {
if (attr.onSelectExpr) {
$scope.OnSelectExpr({ ... }); <<<------ this is not working
}
});
},
}
angular.module("...", ...)
.controller("listCtrl", ListController)
.directive("listControl", listControlDirective());