angularjs - AngularJS 指令加载控制器
问题描述
我正在尝试使用指令、ng-include 和模型参数动态加载控制器,但它不起作用:
主页:
<ng-include src="obj_data.modulo_appendice"
dyn-controller="obj_data.modulo_appendice_controller"
dyn-controller-url="obj_data.modulo_appendice_controller_url"></ng-include>
指示:
WebCauApp.directive('dynControllerUrl', ['$compile', '$parse', function ($compile, $parse)
{
return {
restrict: 'A',
terminal: true,
priority: 200000,
link: function (scope, elem)
{
// Parse the scope variable
var controller = $parse(elem.attr('dyn-controller'))(scope);
var controller_url = $parse(elem.attr('dyn-controller-url'))(scope);
elem.removeAttr('dyn-controller');
elem.removeAttr('dyn-controller-url');
var script = document.createElement('script');
script.type = "text/javascript";
script.setAttribute('src', controller_url);
//var head = angular.element(document.querySelector('head'));
//head.append(script);
elem[0].parentNode.before(script);
elem.attr('ng-controller', controller);
$compile(elem)(scope);
}
}
}]);
错误是参数“mycontrollername”不是函数,未定义
解决方案
推荐阅读
- ios - 当scrollview快速滚动时如何滚动collectionView?
- math - 查找给定(sympy)行列表的中心线
- php - 如何插入多选的新值
- android - 生成 APK 构建时出错并尝试从设备即时应用程序运行它
- elasticsearch - 在elasticsearch中加入文档
- python - 从 FTP 服务器到 Flask 服务器的 Python 流以供下载
- spring - 如何处理 Spring reactor Mono 或 Flux 中的错误?
- objective-c - 从数组中调用元素并将其分配给变量?
- python - 加入两个具有多个值的 Rdd 并基于加入 Pyspark 添加额外的值?
- python - 使用子进程在 python 中发送电子邮件