学无先后,达者为师

网站首页 前端文档 正文

控制器调用指令的方法-angularjs

作者:phoebe_huang 更新时间: 2022-03-15 前端文档

1、指令

scope: {
  setFn: '&'
}

scope.clickDirective = function () {
    console.log('父层调用了我')
}

scope.setFn.call(scope,  {
  params: scope.clickDirective
})


2、引用指令的控制器
html

<test-directive set-fn="setDirectiveFn(params)"></test-directive>

controller

// 把指令的方法绑定到控制器
scope.setDirectiveFn = function (fn) {
   scope.direcitveFn = fn;
}

// 调用
 scope.direcitveFn();

 

原文链接:https://blog.csdn.net/PigBiBiX/article/details/111601036

栏目分类
最近更新