查看未更新

时间:2013-03-07 20:30:25

标签: angularjs

我正在尝试使用角度JS创建一个简单的UI,但似乎无法弄清楚为什么在控制器rpc完成后视图没有得到更新。

<!-- search result view -->
<p>size is {{resultCount}}</p>

<!-- main view which has ng-view -->
<html ng-app="exApp">
    <body ng-controller="exApp.MainCtrl">
        <!-- form which submits to SearchCtrl -->
        <form name="searchform" ng-controller="exApp.SearchCtrl" ng-submit="search()">
            <input type="text" ng-model="queryString">
        </form>
        <div class="view-panel" ng-view></div>
    </body>
</html>
exApp.MainCtrl = function ($scope) {
    $scope.queryString = '';
    $scope.resultCount = 0;
}

exApp.SearchCtrl = function ($scope, $http) {
    function display(response) {
        $scope.poreqs = response["resource"];
        // should update the html, but does not
        $scope.resultCount = $scope.poreqs.length;
    }
    $scope.search = function () {
        $http.get('/search?q=' + $scope.queryString).success(display);
    };
};

0 个答案:

没有答案