I am trying to add a template with a controller using a directive:
<div directOne>
</div>
Directive:
a.directive("direct-one", function ($templateRequest, $compile, $controller) {
return {
link: function (scope, elem, attrs) {
$templateRequest("template.html").then(function (html) {
var $scope = scope.$new();
$controller('oneController', {$scope, $scope});
var template = angular.element(html);
$(elem).append(template);
template = $compile(template)(scope);
});
}
};
});
template:
<span ng-bind="test"></span>
<div ng-controler="oneController">
</div>
controller:
app.controller('oneController', function () {
$scope.test = '123456';
}
My problem that is the test value is not shown.
I have seen some working samples of what I am doing. My real code is more complex.
Hope, someone can help me.
Thanks
Update 1 My code should look like this then:
<div style="width:90%;height:100%">
<div ng-controler="oneController" directOne>
</div>
And that code is a part of another template with its own controller. So, unless I have $scope.test on the parent controller the data is not shown.