使用$scope属性绑定ng-includ-src
binding ng-include src using $scope property
在angularjs应用程序中,我想动态加载部分视图,所以我的视图中有
<ng-include src="'{{ pathView }}'"></ng-include>
这个视图当然附在某个控制器上,在我的控制器中我有
$scope.pathView= "/templates/listView.html";
这不起作用,因为当调查html视图时,我得到了
<!-- ngInclude: undefined -->
当我硬编码模板视图路径时
<ng-include src="'/templates/listView.html'"></ng-include>
它是有效的。
我做错了什么?
ng-include
中的src
需要一个角度表达式引用,因此您可以将其绑定到模型值,如下所示
<ng-include src="pathView"></ng-include>
删除{{
和}}
正确方式<ng-include src="pathView"></ng-include>