我的模板没有更新

时间:2013-10-24 21:44:31

标签: javascript jquery angularjs

MainController.js

app.controller("mainController", function($scope, $http){
$scope.movies = [];
$scope.searchFilter = '';
$scope.init = function() {

};

$scope.getMovies = function(){
    var movieName = $('#MovieName').val();
    var movies = getMovies(movieName); // Gets json
    $scope.parseMovies(movies);    
};

$scope.parseMovies = function(movies){
    $scope.movies = [];
    $.each(movies, function( index, value ) {
        $scope.movies.push($scope.createMovie(value));
    });
};

$scope.createMovie = function(json){
    Movie=new Object();
    Movie.id=json.id;
    Movie.title=json.title;
    Movie.year=json.year;
    Movie.runtime=json.runtime;
    return Movie;
};

});

app.js

var app = angular.module('MoviesApp',[]);

HTML

<body ng-controller="MovieListCtrl">    
    <div class="container main-frame" ng-app="MoviesApp" ng-controller="mainController">
        <input type="text" id="MovieName" />
        <input type="button" data-ng-click="getMovies()" />        
        <ul>
            <li ng-repeat="movie in movies">
                {{movie.title}}
            </li>
        </ul>
    </div>    
</body>

当我点击按钮并调用getMovies()时,数据被检索正常,但模板没有被填充。只有当我再次点击按钮时,它才会被填满。

事情就是当第二次点击它时,模板在检索新的json之前被填充(我在脚本中放了一个断点)。

我被困了

0 个答案:

没有答案