Javascript Angular Js在Ajax之后运行

Javascript Angular Js在Ajax之后运行,javascript,jquery,ajax,angularjs,Javascript,Jquery,Ajax,Angularjs,如何在angular ajax中运行ajax 我有像这样的棱角 Index.html MyApp.controller('MainController', function($scope, $http, $location , $compile) { $scope.content_middle = 'Welcome'; $scope.goto = function(path){ $http.get( pa

如何在angular ajax中运行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>

这将使用ajax加载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>
User.html
不
名称
用户名
日期
行动
{{user.no}
{{user.name}
{{user.username}
{{user.date}
//这将使用ajax加载data.txt
MyApp.controller('UserController',
函数($scope、$http、$location){
$http.get('data.txt').success(函数(响应){
$scope.users=响应;
});
}
);
可能吗? 因为我想用它来进行动态调用。 我在AdvAjax中使用了这种方法,它非常棒

谢谢

最好使用…-通过嵌套视图实现灵活布线的事实解决方案


<a href="" ng-click="goto('user.html')">User</a>
使用
ajax
加载另一个HTML不是一个好选择

对于基本布线,angular具有所需模块的服务

对于高级功能,是用于布线的角度模块。它有
指令
命名为
ui视图
服务
命名为
$state
,用于从一个页面路由到另一个页面。它提供嵌套状态和视图多个命名视图