0

简单的事情 - 在 jsfiddle 中有效,但在我的文件中无效。我正在尝试将一些数据添加到模块的“工厂”,然后在我的控制器中使用它。这是相关代码:

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..
}

和 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>

这里有什么我想念的吗?

4

1 回答 1

3

所以,正如我所怀疑的,这是一个愚蠢的错误。<html>标签是:

<html ng-app>

阻止标签ng-app上的正确属性。<body>

于 2013-02-11T11:57:37.890 回答