AngularJS: Error: Unknown provider

Simple thing - works in the jsfiddle but not in my file. I'm trying to add some data to "factory" of the module and then use it within my controllers. This is the relevant code:

var challengesApp = angular.module('challengesApp', []);
challengesApp.factory('Challenges', function() {
    var challenges = [
        {
            'program': {
                "num": "1",
                "name": "aaa"
            },
            'challengeDesc': "desss",
            'items': [
                {title:"aaa",
                    desc:"bbb",
                    link: "www.google.com",
                    fiction: true},
            ]
        }
    ];
    return challenges;

});


function ChallengeCtrl($scope, Challenges) {
    $scope.challenges = Challenges;
    etc...
}

function ChallengeListCtrl($scope, Challenges) {
    $scope.challenges = Challenges;
    etc..
}

and the HTML:

    <body ng-app="challengesApp">
        <div ng-controller="ChallengeCtrl">
            <div id="question">
                <h2>{{ challenge.challengeDesc }}</h2>
                <ul>
                    <li ng-repeat="item in challenge.items">
                        <strong>{{ item.title }}</strong> - {{ item.desc }}
                    </li>
                </ul>
            </div>
        </div>

        <div ng-controller="ChallengeListCtrl">
            <div id="programs_list">
                <ul>
                    <li ng-repeat="program in challenges | orderBy:orderProp:reverse">
                        <a href="" ng-click="changeChallenge(program)">
                        {{ program.program.num }} - {{ program.program.name }}
                        </a>
                    </li>
                </ul>
            </div>
        </div>


        <script src="js/main.js"></script>
    </body>

anything here that I'm missing?


So, as I suspected, it was a dumb mistake. the <html> tag was:

<html ng-app>

blocking the correct ng-app attribute at the <body> tag.

链接地址: http://www.djcxy.com/p/77630.html

上一篇: 错误在angularjs中注入$ dialog

下一篇: AngularJS:错误:未知提供者