2016-12-14 4 views
1

그래서 JSON 인 API 호출의 일부 데이터를 나열하려고합니다. 나는 앵귤러와 자바 스크립트에 익숙하지 않고 전체 비동기적인 것이 내 논리를 망쳐 놓고 있다고 생각한다. 때로는 페이지를 새로 고침 할 때 완벽하게 작동하지만 예상되는 모든 데이터가 있지만 다음 번에 새로 고침 할 때가 있습니다. 이것은 내가 컨트롤러에서 무언가를 바꿀 때 일어나는 것처럼 보입니다.AngularJS는 더 이상 렌더링되지 않습니다.

var app = angular.module("hasRead", ['hasRead.controllers', 'hasRead.directives', 'hasRead.services', 'hasRead.filters','ngRoute']); 

app.config(["$routeProvider", function ($routeProvider) { 
    $routeProvider 
    .when("/books/:shelf", {controller: "BooksCtrl", templateUrl: "partials/books_list.html"}) 
    .when("/recomend", {controller: "RecomendCtrl", templateUrl: "partials/recomend.html"}) 
    .otherwise({redirectTo: "/books/read"}) 
}]); 

controller.js

var ctrls = angular.module('hasRead.controllers', []); 

ctrls.controller('AppCtrl', function ($scope) { 
}); 

ctrls.controller('BooksCtrl', function ($scope, $book, $routeParams) { 
    $scope.books; 
    var shelf = $routeParams.list; 
    $book.getBooks(shelf).then(function(data) { 
    $scope.books = data.query.results.body.goodreadsresponse.reviews; 
    console.log($scope.books); 
    $scope.$apply; 
    }); 
}); 

ctrls.controller('RecomendCtrl', function ($scope) { 
    $scope.test = "testing"; 
}); 

HTML

<div> 
    <book ng-repeat="review in books.review" review-data="review"></book> 
</div> 

그것 때문에 여기에 코드의 공정한 비트는 plunkr입니다 : https://plnkr.co/edit/l3A6QF?p=info

+0

플 런커가 작동하지 않습니다. (정확하게 연결되지 않은 각도), figure 지시어가 빠졌고 $ scope. $ apply() 함수는 괄호를 추가하고 더 잘 작동하는지 확인합니다. – gyc

+0

앱을 실행하지 않도록 코드를 볼 수있게되었습니다. – James

+0

예, 그게 제가 생각한 것입니다. 기쁜 데 도움이되었습니다. – gyc

답변

0

내가 괄호가 없었어요 컨트롤러의 $scope.$apply();에 있습니다.

관련 문제