0

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?

SnirD
  • 708
  • 11
  • 22
  • Are you, by any chance, minifing files in your target app? If not maybe you are simply missing `ng-app='challengesApp'`? Hard to say more without seeing live code... – pkozlowski.opensource Feb 10 '13 at 15:42
  • @pkozlowski.opensource as you can see from my code - right in the body tag: so that's not the issue. and i'm not minifing... – SnirD Feb 10 '13 at 16:02
  • 2
    In this case it will be very hard to help more, since the code you've posted works OK in plunker: http://plnkr.co/edit/RWJqbJ2EOu0FgCpqnxiz?p=preview The only fishy thing is an additional comma at the end of JSON data. You can eventually check http://stackoverflow.com/q/12339272/1418796 – pkozlowski.opensource Feb 10 '13 at 16:22

1 Answers1

3

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.

Matt Mills
  • 8,692
  • 6
  • 40
  • 64
SnirD
  • 708
  • 11
  • 22