0

我正在尝试使用 Angular 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);
    };
};
4

0 回答 0