please check this Link
here is my question how can I bind a controller to Page2Controller to print some thing in
{{wat}}
please check this Link
here is my question how can I bind a controller to Page2Controller to print some thing in
{{wat}}
The simple way is to use $compile
in the controller.
Compiles an HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together.
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope, $http, $sce, $compile) {
$scope.wat = 'blablalba';
$http.get("page2.html").then(function (response) {
var str = '<div ng-controller="Page2Controller"> {{wat}} <div style="background: red; height: 50px; width: 50px"></div> </div>';
var cont = $compile(response.data)($scope);
angular.element(document.querySelector('p')).append(cont);
});
});
app.controller('Page2Controller', function($scope) {
});
<div ng-app="myApp" ng-controller="myCtrl">
<p></p>
</div>
http://plnkr.co/edit/cOu69mPhfrvaA1buDUjT?p=preview
The better way is to using a directive like in this answer: Compiling dynamic HTML strings from database