AngularJS ng-include does not include view unless passed in $scope

后端 未结 2 1659
不知归路
不知归路 2020-12-04 09:45

Is it wrong to assume that ngInclude can take a raw path? I keep trying to set my ngInclude as follows:

相关标签:
2条回答
  • 2020-12-04 10:26

    ng-include accepts an expression. If you want to specify the explicit URL directly in there, you have to give a string.

    <div ng-include src="'page.html'"></div>
    
    0 讨论(0)
  • 2020-12-04 10:45

    ng-include, as other directives (ng-class, ng-src ...) evaluates an Angular expression from the scope. Without quotes (''), it will search for a variable of the scope.


    Note that you don't have to specify the src attribute.

    <div ng-include src="'views/header.html'"></div>
    

    Can be rewritted to: (that is simpler)

    <div ng-include="'views/header.html'"></div>
    

    You can also use ng-include as an element:

    <ng-include src="'views/header.html'"></ng-include>
    
    0 讨论(0)
提交回复
热议问题