2014-11-21 7 views
1

ng-app를 사용하여 AngularJS 컨트롤러를 만들고 있지만 제대로 작동하지 않습니다.AngularJS 오류 - "컨트롤러가 정의되지 않았습니다"또는 "함수가 정의되지 않았습니다"

Chrome 콘솔에서 angular ctrl is not defined 또는 not a function got undefined 오류가 발생합니다.

겨 - 응용 프로그램 :

var localizationModule = angular.module("localizationModule",[]); 

Controller.js

localizationModule.controller('localizationCtrl', ['$scope', 
function ($scope) { 
$scope.local = { 
    ProjectSingular: '', 
    ProjectPlural: '', 
    ServiceObjectSingular: '', 
    ServiceObjectPlural: '', 
    ServicePictureSingular: '', 
    ServicePicturePlural: '', 
} 

$scope.Save = function (local) { 
    console.log(local); 
} 
}]) 

HTML

<form ng-app="localizationModule" ng-controller="localizationCtrl"> 
<div class="panel panel-info"> 
    <div class="panel-heading"> 
     <strong>Localization Setting</strong> 
    </div> 
    <div class="panel-body"> 

     <div class="row"> 
     </div> 
     <div class="row"> 
      <div class="col-lg-12"> 
       <div class="table-responsive"> 
        <table class="table table-striped table-hover table-bordered"> 
         <tr> 
          <th>Elements</th> 
          <th>Singular</th> 
          <th>Plural</th> 
         </tr> 
         <tr> 
          <td>Project</td> 
          <td><input type="text" required ng-model="local.ProjectSingular" class="form-control" /></td> 
          <td><input type="text" required ng-model="local.ProjectPlural" class="form-control" /></td> 
         </tr> 
         <tr> 
          <td>Service Object</td> 
          <td><input type="text" required ng-model="local.ServiceObjectSingular" class="form-control" /></td> 
          <td><input type="text" required ng-model="local.ServiceObjectPlural" class="form-control" /></td> 
         </tr> 
         <tr> 
          <td>Service Picture</td> 
          <td><input type="text" required ng-model="local.ServicePictureSingular" class="form-control" /></td> 
          <td><input type="text" required ng-model="local.ServicePicturePlural" class="form-control" /></td> 
         </tr> 
        </table> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div class="panel-heading"> 
     <input type="submit" class="btn btn-success pull-right" value="Save" /> 
     <div class="clearfix"></div> 
    </div> 
</div> 
</form> 

크롬 콘솔

Error: [ng:areq] http://errors.angularjs.org/1.2.17/ng/areq?p0=localizationCtrl&p1=not%20a%20function%2C%20got%20undefined at Error (native) at http://localhost:1914/Scripts/angular.min.js:6:450 at Cb (http://localhost:1914/Scripts/angular.min.js:19:130) at Sa (http://localhost:1914/Scripts/angular.min.js:19:217) at http://localhost:1914/Scripts/angular.min.js:66:451 at http://localhost:1914/Scripts/angular.min.js:53:250 at q (http://localhost:1914/Scripts/angular.min.js:7:386) at N (http://localhost:1914/Scripts/angular.min.js:53:115) at g (http://localhost:1914/Scripts/angular.min.js:47:82) at http://localhost:1914/Scripts/angular.min.js:46:256

+0

두 가지 : 파일을로드하는 스크립트 태그를 작성했습니다 있는지 확인하고 자식 DIV에 컨트롤러를 이동하려고 .. – harishr

+0

나는 아무 잘못 찾을 수 없습니다. 나는 각진 v1.2.1로 테스트했고 모두 괜찮습니다. 그래서 각도 버전이나 스크립트로드 오류가 잘못 되었습니까? – creeper

+0

나는 양쪽 방법을 시도했지만 문제는 여전히 여기에있다 –

답변

0

script inlined: jsFiddle와 함께 잘 작동하므로 위의 주석으로 스크립트로드의 타이밍은, 의심이다.

(BTW. 닫는 </form>

+0

여기에 쓰는 것을 잊어 버렸습니다. –

0

: 실종 보인다 나는 각도에서 사소한 버그를 발견했습니다. 컨트롤러와 같은 파일에 모듈 선언이 있습니까? Id 모든 컨트롤러 파일에서 종속성 삽입 배열없이 모듈을 선언하려고합니다.

angular.module("localizationModule").controller('localizationCtrl', ['$scope', 
function ($scope) { 
$scope.local = { 
    ProjectSingular: '', 
    ProjectPlural: '', 
    ServiceObjectSingular: '', 
    ServiceObjectPlural: '', 
    ServicePictureSingular: '', 
    ServicePicturePlural: '', 
} 

$scope.Save = function (local) { 
    console.log(local); 
} 
}]) 

파일은 반드시 iioife로 포장하십시오.

(function(){ 

//---code-- 

})(); 
관련 문제