ng-include禁止运行路由

时间:2013-03-17 23:23:36

标签: angularjs

我在AngularJS应用程序中有一个非常奇怪的行为:我正在使用$ routeProvider注册路由。除非我在ng-include之前嵌入ng-view元素 ,否则这种方式非常有效。

目前我有两种方法可以解决它:

  • ng-include移至ng-view元素后面的位置。
  • ng-include包裹在<div>元素内。

知道可能导致此问题的原因吗?

2 个答案:

答案 0 :(得分:1)

尝试

    <div ng-controller="MainCtrl" ng-include src="template">

    angular.module('App')
        .controller('MainCtrl',['$route','$scope', function($route,$scope){
                $scope.template= 'main.html';
        }]);

In main.html, place the ng-view tag.

在这种情况下,您需要使用控制器处理ng-include并将$ route作为依赖项注入。

答案 1 :(得分:0)

我也遇到过$ route的问题。 解决我的问题的一个想法是只使用ng-switch代替ng-include而不是ng-view Conditional ng-include in angularjs

相关问题