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?

3
  • 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... Commented Feb 10, 2013 at 15:42
  • @pkozlowski.opensource as you can see from my code - right in the body tag: <body ng-app="challengesApp"> so that's not the issue. and i'm not minifing... Commented Feb 10, 2013 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: plnkr.co/edit/RWJqbJ2EOu0FgCpqnxiz?p=preview The only fishy thing is an additional comma at the end of JSON data. You can eventually check stackoverflow.com/q/12339272/1418796 Commented Feb 10, 2013 at 16:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.