我正在尝试通过指令将模板传递给动态控制器(从指令的角度在运行时已知)。
像这样的东西:
<my-dir ctrl="PersonCtrl">
<h1>{{person.name}} - {{person.age}}</h1>
</my-dir>
var data = {
name: "Alex",
age: "24"
};
function PersonCtrl($scope){
$scope.person = data;
}
myApp.directive('myDir', function($controller){
return {
restrict: "EA",
scope: {
ctrl: "@"
},
transclude: true,
controller: function($scope, $element, $attrs) {
},
template: "<div>{{ctrl}}</div><div ng-transclude></div>",
link: function($scope, $element, $attrs) {
$controller($attrs.foo, {$scope: {}});
}
};
});
找到并实例化了控制器,但不知何故,将嵌入的模板绑定到它不起作用。我错过了一些订单要求还是有办法将此控制器范围绑定到嵌入模板?