有角度和烧瓶的麻烦 - 错误消息含糊不清

时间:2014-12-05 22:14:12

标签: angularjs flask

无法获取角度来读取通过服务获取的对象。浏览器中的错误消息实际上是vauge,不会引用我的任何代码行。我通过Chrome开发人员工具进行了检查,并且正在进行API调用。有什么想法吗?

错误讯息:

TypeError: undefined is not a function
    at copy (http://127.0.0.1:5000/static/lib/angular/angular.js:593:21)
    at http://127.0.0.1:5000/static/lib/angular/angular-resource.js:410:19
    at wrappedCallback (http://127.0.0.1:5000/static/lib/angular/angular.js:6846:59)
    at http://127.0.0.1:5000/static/lib/angular/angular.js:6883:26
    at Object.Scope.$eval (http://127.0.0.1:5000/static/lib/angular/angular.js:8057:28)
    at Object.Scope.$digest (http://127.0.0.1:5000/static/lib/angular/angular.js:7922:25)
    at Object.Scope.$apply (http://127.0.0.1:5000/static/lib/angular/angular.js:8143:24)
    at done (http://127.0.0.1:5000/static/lib/angular/angular.js:9170:20)
    at completeRequest (http://127.0.0.1:5000/static/lib/angular/angular.js:9333:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://127.0.0.1:5000/static/lib/angular/angular.js:9303:11)

服务:

angular.module('angularFlaskServices', ['ngResource'])
  .factory('Pic', function($resource) {
    return $resource('/api/pic/:picId', {}, {
      query: {
        method: 'GET',
        params: { picId: '' },
        isArray: true
      }
    });
  })
;

角度控制器:

function ProfileController($scope, Pic) {
    var picsQuery = Pic.get(function(pics) {
        $scope.pics = pics;
    });
}

烧瓶视图:

@app.route('/api/pic/')
def on_recent(): 
    if not session.has_key('access_token'):
        return 'Missing Access Token'
    try:
        api = client.InstagramAPI(access_token=session['access_token'])
        recent_media, next = api.user_recent_media()
        print recent_media
        photos = []
        for media in recent_media:
            if (media.type != "video"):
                photos.append({"picId": 1, "url": media.get_low_resolution_url()})
    except Exception as e:
        print(e)              
    return json.dumps(photos) 

1 个答案:

答案 0 :(得分:0)

您的服务代码看起来不错,但我不确定您是否已正确注入所有依赖项。

var app = angular.module('myApp', ['angularFlaskServices']);
app.controller('ProfileController', [
  '$scope',
  'Pic',
  function($scope, Pic) {
     var picsQuery = Pic.get(function(pics) {
       $scope.pics = pics;
     });
}]);