未捕获的引用错误:未定义$scope - AngularJS
Uncaught ReferenceError: $scope is not defined - AngularJS
我是使用AngularJS
的新手。但是,为什么这不起作用?
加载网页后,我进入控制台Uncaught ReferenceError: $scope is not defined
第 81
行哪个是$scope.processForm = function() {
帮助?
// define angular module/app
var formApp = angular.module('formApp', []);
// create angular controller and pass in $scope and $http
function formController($scope, $http) {
// create a blank object to hold our form information
// $scope will allow this to pass between controller and view
$scope.formData = {};
// process the form
$scope.processForm = function() {};
}
// process the form
$scope.processForm = function() {
$http({
method: 'POST',
url: 'process.php',
data: $.param($scope.formData), // pass in data as strings
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
} // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
console.log(data);
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorSuperhero = data.errors.superheroAlias;
} else {
// if successful, bind success message to message
$scope.message = data.message;
}
});
};
<!-- LOAD ANGULAR -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<!-- LOAD BOOTSTRAP CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<!-- LOAD JQUERY -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<body ng-app="formApp" ng-controller="formController">
<div class="container">
<div class="col-sm-6 col-sm-offset-3">
<!-- PAGE TITLE -->
<div class="page-header">
<h1><span class="glyphicon glyphicon-tower"></span> Submitting Forms with Angular</h1>
</div>
<!-- SHOW ERROR/SUCCESS MESSAGES -->
<div id="messages" ng-show="message">{{ message }}</div>
<!-- FORM -->
<form ng-submit="processForm()">
<!-- NAME -->
<div id="name-group" class="form-group" ng-class="{ 'has-error' : errorName }">
<label>Name</label>
<input type="text" name="name" class="form-control" placeholder="Bruce Wayne" ng-model="formData.name">
<span class="help-block" ng-show="errorName">{{ errorName }}</span>
</div>
<!-- SUPERHERO NAME -->
<div id="superhero-group" class="form-group" ng-class="{ 'has-error' : errorSuperhero }">
<label>Superhero Alias</label>
<input type="text" name="superheroAlias" class="form-control" placeholder="Caped Crusader" ng-model="formData.superheroAlias">
<span class="help-block" ng-show="errorSuperhero">{{ errorSuperhero }}</span>
</div>
<!-- SUBMIT BUTTON -->
<button type="submit" class="btn btn-success btn-lg btn-block" ng-model="formData.XAlias">
<span class="glyphicon glyphicon-flash"></span> Submit!
</button>
</form>
</div>
</div>
<!-- SHOW DATA FROM INPUTS AS THEY ARE BEING TYPED -->
<pre>{{formData}}</pre>
将控制器 ( function formController($scope, $http)
( 内的空$scope.processForm
替换为当前外部的空。
在控制器内部,它将可以访问您注入的$scope
。
相关文章:
- scope.$apply 是未定义的,在 scrolly 指令中不起作用
- 从服务返回值时$scope控制器的变量是未定义的
- scope() 函数在 AngularJS 控制器中返回未定义
- $scope.form.$error在Angular控制器中未定义
- AngularJS$scope在指令中编译控制器时未定义
- 表单提交中未定义角度$scope
- $scope变量在指令隔离作用域中未定义
- $scope变量未定义,尽管它是在$watch函数内部设置的
- 离子框架:$scope在简单警报中未定义
- 未捕获的引用错误:未定义$scope - AngularJS
- $scope在模态角 js 中未定义
- 茉莉花/棱角.js $scope在加载控制器上未定义
- AngularJS $scope.variable 是未定义的
- AngularJs $scope在离子项目中是未定义的
- 无法读取未定义的属性“$scope”
- 无法在茉莉花测试中调用$scope.form.$submitted:未定义
- Angular ES6,THIS,Scope和EL在JQLITE点击事件中全部未定义
- 分页角度$scope变量是未定义的
- 在指令中使用 $scope.$watch 处理未定义变量的替代方法
- Angular指令中未定义Scope对象