0

I have a standard app:

angular.module('angularFrontApp', [
    'ngRoute',
    'ngResource',
    'ngAnimate'
]).config(AppConfig);

and some controller

angular.module('angularFrontApp')
    .controller('formsController', formsController);

formsController.$inject = ['$scope', 'AjaxForms', 'appConst'];
function formsController ($scope, AjaxForms, appConst) {

    //.....
}

I am trying call a controller in ng-include, but it fails in dynamicTemplate (its dynamic var like some.html):

<div ng-include="dynamicTemplate"></div>


<div ng-controller="formsController">some stuff....</div>

But if I call the controller outside of include - it works fine. Why doesn't angular see controllers and other things in includes?

WebArtisan
  • 3,996
  • 10
  • 42
  • 62

1 Answers1

0

Because your ng-include is wrong: ng-include takes an expression not a string.

<div ng-include="'some.html'"></div>
  • I have no trouble with includes. All content rendered fine. What if it dynamic include from variable? ng-include="dynamicTemplate". How can i include that? – WebArtisan Jan 23 '16 at 10:54
  • @Oleg_webdev: you can use variables. In my front apps, i store variables in the controller like $scope.url.header , and ng-include="url.header". By doing this, I can add suffix in the url (like `'mytemplate?v=' + build_id`), which allows the application to avoid cache problems when I update the website. If you don't need to take in consideration the cache, you can use strings. – Pierre Emmanuel Lallemant Jan 23 '16 at 10:57
  • Still not work. 1) angularjs can include strings without single quotes 2) i include template with variable. Included content rendering but won't find controller – WebArtisan Jan 23 '16 at 11:08
  • @Oleg_webdev: http://stackoverflow.com/questions/27087730/angularjs-ng-include-and-ng-controller – Pierre Emmanuel Lallemant Jan 23 '16 at 11:15
  • What if controller comes from ng-bind-html? I got data from db put into
    and this data contains
    – WebArtisan Jan 23 '16 at 11:40