【发布时间】:2016-05-27 16:35:04
【问题描述】:
从模板编译后,是否可以动态关联控制器?
//Controller /path/ctrl/MainCtrl.js
angular.module('app')
.controller('MainCtrl', function () {
});
//Directive /path/dir/myDir.js
function link(scope, element, attrs) {
$templateRequest('path/oneTpl.tpl').then(function (html) {
$compile(element.html(html).contents())(scope);
//How can I do to dynamically inject MainCtrl into the oneTpl.tpl template using the path (/path/ctrl/MainCtrl.js)?
});
}
【问题讨论】:
标签: javascript angularjs angularjs-directive angular-template angular-controller