我正在尝试将route属性绑定到ng-include的src。
config.js
$routeProvider.when('/services', {
templatePATH: '/views/services.html'
});index.html
<html lang="en" ng-app="myApp" ng-controller="AppController">
<body>
<div ng-include src="{{page}}" class="container"></div>
</body>
</html>controllers.js
controller('AppController', ['$scope','$route','$routeParams', function($scope, $route, $routeParams) {
var render = function(){
$scope.page = $route.current.templatePATH;
};
$scope.$on("$routeChangeSuccess",function( $currentRoute, $previousRoute ){
render();
});
}]).Here's where I got the idea.奇怪的是,templateURL的值可以在页面上的DOM中看到,其中src是从ng-include指令注入的。然而,令人遗憾的是,这是行不通的。
有可能达成这样的约定吗?
发布于 2013-06-13 18:30:52
哦,你只是犯了一个很小的错误,请把你的代码改为下面的代码
<div ng-include="page" class="container"></div>更详细的答案:当您使用ng-include指令时,会在srcExp上放置一个手表,它的值为attr.ngInclude \x\\ attr.src,所以如果您使用{ page }},那么您将监视页面的值,而不是页面属性上的值,因此您必须在没有内插值的情况下放置" page“,以便它可以直接在页面上而不是在页面字符串值上观看。
https://stackoverflow.com/questions/17091713
复制相似问题