2013-02-10 98 views
0

簡單的事情 - 在jsfiddle中工作,但不在我的文件中。我試圖添加一些數據到模塊的「工廠」,然後在我的控制器中使用它。 這是相關代碼:AngularJS:錯誤:未知提供者

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> 

東西在這裏,我失蹤?

+0

您是否有任何機會在您的目標應用程序中減少文件?如果不是,你可能只是缺少'ng-app ='challengesApp''?很難說更多沒有看到現場代碼... – 2013-02-10 15:42:04

+0

@ pkozlowski.opensource,你可以從我的代碼中看到 - 正確的身體標籤:所以這不是問題。並且我不會縮小... – SnirD 2013-02-10 16:02:50

+2

在這種情況下,將很難提供更多幫助,因爲您發佈的代碼在plunker中可以正常工作:http://plnkr.co/edit/RWJqbJ2EOu0FgCpqnxiz?p=preview The只有在JSON數據結束時纔會有一些額外的逗號。您最終可以檢查http://stackoverflow.com/q/12339272/1418796 – 2013-02-10 16:22:38

回答

3

所以,正如我懷疑的那樣,這是一個愚蠢的錯誤。在<html>標籤是:

<html ng-app> 

<body>標籤擋住了正確ng-app屬性。

相關問題