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?

1 Answer 1

0

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

<div ng-include="'some.html'"></div>
Sign up to request clarification or add additional context in comments.

5 Comments

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?
@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.
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
What if controller comes from ng-bind-html? I got data from db put into <div ng-bind-html="..."> and this data contains <div ng-controller="someController"... How can i get this controller ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.