Ido
Ido

Reputation: 51

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

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

Upvotes: 0

Views: 137

Answers (1)

csbenjamin
csbenjamin

Reputation: 356

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);
})

Upvotes: 2

Related Questions