2014-06-11 4 views
0

정말 간단한 Angular JS 응용 프로그램이 있는데 왜 오류가 발생하는지 알 수 없습니다. 오류 : [ng : areq] Arguments 'CoursesController'는 함수가 아닙니다. 정의되지 않은Angular JS가 컨트롤러를 등록 할 수 없습니다.

내 바이올린 (당신은 콘솔에서 오류를 확인하기 위해서는 브라우저의 개발 도구를 열어야합니다) : http://jsfiddle.net/Y4c2q/

내 각도 JS 코드 :

'use strict'; 
console.log('reg module entry'); 
var registrationModule = angular.module('registrationModule', []); 

registrationModule.controller('CoursesController', function ($scope, bootStrappedData) { 
    $scope.courses = bootStrappedData.courses; 
    console.log('inside of controller'); 
}); 

registrationModule.factory('bootStrappedData', function() { 
    console.log('bootstrapping our data'); 
    return { 
courses: [{"number":"aaa","name":"magical creatures","instructor":"John"}, 
      {"number":"bbb","name":"ze dark arts","instructor":"Rob"}, 
      {"number":"ccc","name":"third book","instructor":"Bran"}] 
    }; 
}); 

이 내가 원하는 HTML입니다 내 3 행의 데이터를 표시하려면

<div ng-controller="CoursesController"> 
    <table class="table table-condensed table-hover"> 
     <tr> 
      <th>Course</th> 
      <th>Course Name</th> 
      <th>Instructor</th> 
     </tr> 
     <tr ng-repeat="course in courses"> 
      <td>{{course.number}}</td> 
      <td>{{course.name}}</td> 
      <td>{{course.instructor}}</td> 
     </tr> 
    </table> 
</div> 
+0

어떻게 응용 프로그램을 부트 스트랩합니까? 'ng-app' 또는 수동으로 사용 하시겠습니까? 'registrationModule'은 메인 어플리케이션 모듈에 대한 의존성으로 표시되어 있습니까? – package

+0

내 바이올린을 확인 했습니까? 귀하의 질문을 정확하게 이해했다면이 링크 (https://docs.angularjs.org/guide/bootstrap)에 따라 자동 부트 스트랩을 사용했음을 확신합니다. – Tomas

답변

4

이 오류는 ng-app 선언에 모듈 이름이 없기 때문에 발생합니다. 이

ng-app='registrationModule'

이보기에 당신의 모듈 및 컨트롤러를 연결 할 수 있습니다.

관련 문제