从手动$compile调用中获取控制器
Get the controller from a manual $compile invocation
我正在使用以下命令手动渲染指令。
我怎么能得到控制器实例化背后的编译步骤,与my-directive
指令相关联的场景?
function renderDirective(hostElement) {
var $injector, $compile, link;
$injector = hostElement.injector();
$compile = $injector.get('$compile');
link = $compile(angular.element('<my-directive></my-directive>'));
// ... how can I get the controller instance
// associated with the instance of my-directive
// that has been instantiated by the previous
// line of code?
return link(createScope());
}
my-directive.js
return function MyDirective() {
return {
scope: {
'context': '='
},
restrict: 'E',
template: template,
controller: 'myController',
controllerAs: 'ctrl',
replace: true,
};
};
试试这个:
function renderDirective(hostElement) {
var $injector, $compile, link;
$injector = hostElement.injector();
$compile = $injector.get('$compile');
link = $compile('<my-directive></my-directive>');
// ... how can I get the controller instance
// associated with the instance of my-directive
// that has been instantiated by the previous
// line of code?
return link(createScope());
}
相关文章:
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- ROR:如何在不重新加载浏览器的情况下从控制器获取参数
- Ui路由器:获取控制器中视图的名称
- CodeIgniter:用于获取包括图像在内的值的控制器
- 使用ajax在同一页面中获取控制器动作渲染
- 在控制器中按ID获取XML ViewElement(MultiInput)
- 我正在使用角度 ui-select 进行下拉.如何在控制器中获取所选值
- 从填充了 AJAX 的下拉列表中获取控制器的操作方法中的值
- 从 javascript 获取 MVC 控制器中的操作参数时出错
- 在 AngularJS 中按路径位置获取控制器
- 使用打字稿从回调中获取控制器引用
- 从视图、代码点火器获取控制器中传递的值
- Angularjs.获取控制器的范围.未知的提供程序错误
- 正在获取控制器的null值's使用jquery从javascript传递的操作
- 正在AngularJS中从$parent获取控制器名称
- 获取控制器中$scope的指令值
- 从手动$compile调用中获取控制器
- 在单元测试中获取控制器的编译模板
- 正在获取控制器内部的视图名称
- 如何获取控制器中用户选择的单选按钮的值