Angular Js在Ajax后运行

问题描述:

如何在角度ajax内运行ajax?Angular Js在Ajax后运行

我的角度是这样

Index.html 

MyApp.controller('MainController', 
    function($scope, $http, $location , $compile) { 
     $scope.content_middle = 'Welcome';    

     $scope.goto = function(path){ 
      $http.get(path).success(function(response) { 
       $scope.content_middle = $compile(response) 
      }); 
     } 
    } 
); 

然后一些锚

<a href="" ng-click="goto('user.html')">User</a> 

这将加载user.html阿贾克斯。

User.html 
<table class="table table-hover" ng-controller="UserController"> 
<thead> 
    <tr> 
     <th>No</th> 
     <th>Name</th> 
     <th>Username</th> 
     <th>Date</th> 
     <th>Action</th> 
    </tr> 
</thead> 
<tbody ng-repeat="user in users"> 
    <tr> 
     <td>{{user.no}}</td> 
     <td>{{user.name}}</td> 
     <td>{{user.username}}</td> 
     <td>{{user.date}}</td> 
     <td></td> 
    </tr> 
</tbody> 
</table> 

<script type="text/javascript"> 
// this will load data.txt with ajax angular 
MyApp.controller('UserController', 
    function($scope, $http, $location) { 
     $http.get('data.txt').success(function(response) { 
      $scope.users = response; 
     }); 
    } 
); 
</script> 

这可能吗? 因为我想用它进行动态调用。 我在AdvAjax及其宏伟中使用了这种方式。

感谢

<a href="" ng-click="goto('user.html')">User</a> 

使用加载另一个ajax HTML是不是好的选择。

对于基本路由角具有所需ngRoute模块$routeProvider服务。

对于预先特征,AngularUI Router为路由角模块。它directive命名ui-viewservice命名为$state路由从一个网页到另一个。它提供嵌套国&意见多&命名视图

最好使用... AngularUI Router - 事实上的解决方案,灵活的路由与嵌套视图