Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么我会得到一个infdig错误?_Angularjs - Fatal编程技术网

Angularjs 为什么我会得到一个infdig错误?

Angularjs 为什么我会得到一个infdig错误?,angularjs,Angularjs,我得到一个infdig错误,我在下面的代码中有范围。$apply。为什么会这样?我尝试了很多东西,浏览了很多文档和博客,但我似乎仍然无法理解这一点:( 咖啡 fantasyCricket = angular.module('fantasyCricket', [() -> # Initialises Parse SDK. Parse.initialize("####", "####") # Initialises Parse FacebookUtils. P

我得到一个
infdig
错误,我在下面的代码中有
范围。$apply
。为什么会这样?我尝试了很多东西,浏览了很多文档和博客,但我似乎仍然无法理解这一点:(

咖啡

fantasyCricket = angular.module('fantasyCricket', [() ->
    # Initialises Parse SDK.
    Parse.initialize("####", "####")

    # Initialises Parse FacebookUtils.
    Parse.FacebookUtils.init({
        appId: "####"
        cookie: true
        xfbml: true
    })
])

fantasyCricket.filter('sortByCricket', () ->
    lastOutput = null
    lastInput = null
    (cricketers) ->
        if lastInput isnt cricketers
            lastOutput = cricketers.sort((a, b) ->
                pts = b.total - a.total
                if pts is 0 then a.value - b.value else pts
            )
        else
            lastOutput
)

fantasyCricket.factory('Players', () ->
    found = false
    obj = {
        data: {
            all: []
        }
        getAll: (scope, force) ->
            if (found is false) or (force is true)
                (new Parse.Query(Parse.Object.extend('player'))).find().done((players) ->
                    obj.data.all.push.apply(obj.data.all, players.map((player) ->
                        newPlayer = player.attributes
                        newPlayer.id = player.id
                        newPlayer.total = newPlayer.batPts + newPlayer.bwlPts + newPlayer.fldPts + newPlayer.wins + (newPlayer.matches * 2)
                        newPlayer
                    ))
                    found = true
                    scope.$apply()
                ).fail((err) -> alert('Failed to load players.'))
    }
)

fantasyCricket.factory('Settings', () ->
    found = false
    obj = {
        data: {
            players: 0
            budget: 0
            transfers: 0
        }
        get: (scope, force) ->
            if (found is false) or (force is true)
                (new Parse.Query(Parse.Object.extend('setting'))).find().done((settings) ->
                    settings.forEach((setting) ->
                        obj.data[setting.get('key')] = setting.get('value')
                    )
                    found = true
                    scope.$apply()
                ).fail((err) -> alert('Failed to load settings.'))
    }
)

fantasyCricket.controller('PlayersCtrl', ['$scope', 'Players', ($scope, Players) ->
    $scope.players = Players.data
    Players.getAll($scope)
])

fantasyCricket.controller('InfoCtrl', ['$scope', 'Settings', ($scope, Settings) ->
    $scope.settings = Settings.data
    Settings.get($scope)
])
index.html.jade

head
    meta(charset='utf-8')
    title Badsey Fantasy Cricket
    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js')
    script(src='https://www.parse.com/downloads/javascript/parse-1.2.18.min.js')
    script(src='vendor/facebook/all.js')
    link(rel='stylesheet', href='index.css')

body()
    div(ng-app='fantasyCricket')
        #info(ng-controller='InfoCtrl')
            | Budget: {{settings.budget}},
            | Transfers: {{settings.transfers}},
            | Players: {{settings.players}}

        #players(ng-controller='PlayersCtrl')
            table
                thead
                    tr
                        th.name Name
                        th.more MP
                        th.more Wins
                        th.more Bat
                        th.more Bwl
                        th.more Fld
                        th Total
                        th Value
                tbody
                    tr(ng-repeat='player in (players.all | sortByCricket)' class='{{true ? "Yolo" : "Troll"}}')
                        td.name {{player.name}}
                        td.more {{player.matches}}
                        td.more {{player.wins}}
                        td.more {{player.batPts}}
                        td.more {{player.bwlPts}}
                        td.more {{player.fldPts}}
                        td {{player.total}}
                        td {{player.value}}

    script(src='http://code.jquery.com/jquery-2.1.1.min.js')
    script(src='index.js')

问题是过滤器每次都提供不同的数组,因此导致循环。

大量代码、coffescript、jade、Facebook API……也许有机会简化您的测试用例?我不明白哪里出了问题,所以我认为最好提供所有代码。