how to inject my main.html to my index.php div by angularjs injector and compile

138 views Asked by At

html file at my front end and i need to inject it to my index.php div #container with angularjs injector and compile i'm little new with angular may somebody help ?

at first i tried to do it via ng-include like that

<div id="container" ng-include src="'<?= PATH_FRONT_END ?>main.html'"></div>

but i need by injector and compile something like this angular.injector(['ng']).invoke(['$compile', '$rootScope', function(compile, rootScope){ var scope = rootScope.$new(); scope.bar = "ok!";

    var result = compile('<div>{{main.html}}</div>')(scope);
    $("#foo").append(result.html());
  }]);

but withe a link to my main.html

1

There are 1 answers

0
csbenjamin On BEST ANSWER

You need get the html using the $http service. You code should be something like this:

$http.get("path/to/your/html/main.html").success(function (response) {
    var result = compile(response)(scope);
    $("#foo").append(result);
})