AngularJS UncaughtReferenceError: 컨트롤러가 모듈에서 정의되지 않았습니다.
저는 다음 코드를 가지고 있습니다.
var app =
angular.
module("myApp",[]).
config(function($routeProvider, $locationProvider) {
$routeProvider.when('/someplace', {
templateUrl: 'sometemplate.html',
controller: SomeControl
});
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
});
app.controller('SomeControl', ...);
다음 오류가 발생합니다.
Uncaught ReferenceError: SomeControl is not defined from myApp
$routeProvider를 사용할 때 app.controller('SomeControl', ...) 구문을 사용할 수 없다는 것이 문제입니까?는 유일하게 작동하는 구문입니다.
function SomeControl(...)
따옴표 사용:
controller: 'SomeControl'
Foo L의 말대로 따옴표를 붙여야 합니다.SomeControl
. 따옴표를 사용하지 않으면 변수를 참조하는 것입니다.SomeControl
, 컨트롤러를 나타내는 데 명명된 함수를 사용하지 않았기 때문에 정의되지 않았습니다.
당신이 말한 대안을 사용할 때,function SomeControl(...)
, 당신은 그 명명된 함수를 정의합니다.그렇지 않으면 Angular는 컨트롤러를 검색해야 한다는 것을 알아야 합니다.myApp
모듈.
사용.app.controller('SomeControl', ...)
구문은 전역 네임스페이스를 오염시키지 않기 때문에 더 좋습니다.
위의 답변이 맞지만, 이 오류가 발생할 수도 있습니다.
- html 또는 jspetc 페이지의 컨트롤러 이름이 실제 cotcontroller와 일치하지 않는 경우
<div ng-controller="yourControllerName as vm">
- 또한 기능 컨트롤러의 이름이 컨트롤러 정의와 일치하지 않을 경우에도 이 오류가 발생할 수 있습니다.
angular.module('smart.admin.vip') .controller('yourController', yourController); function yourController($scope, gridSelections, gridCreationService, adminVipService) { var vm = this; activate();
언급URL : https://stackoverflow.com/questions/17454782/angularjs-uncaught-referenceerror-controller-is-not-defined-from-module
'programing' 카테고리의 다른 글
MySQL 확장 디스플레이 (0) | 2023.10.12 |
---|---|
Angular 지시문에서 돔 요소에 액세스하는 방법 (0) | 2023.10.12 |
WooCommerce - 사용자 지정 썸네일 및 기본 폴백 이미지 자리 표시자 (0) | 2023.10.07 |
Oracle SQL에서 정규식과 일치하는 문자열의 일부를 가져오는 방법 (0) | 2023.10.07 |
안드로이드 9.0(파이)에서 야간 모드가 활성화되어 있는 경우에도 애플리케이션에서 야간 모드를 비활성화하는 방법은 무엇입니까? (0) | 2023.10.07 |