简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM