AngularJS推送不起作用
AngularJS push not working
我的angularJS推送选项不起作用。有人能告诉我哪里出了问题,并解决它吗?我开始学这门语言才一个星期。如果这个错误很愚蠢,请原谅我。
谢谢
<body ng-app="app" ng-controller ="Ctrl" >
<style>
.alert{
color: crimson;
font-size: 19px;
}
.form{
width: 72%;
margin-left: 12%;
border: 2px solid gold;
}
</style>
<script>
var app = angular.module("app", []);
app.controller("Ctrl", function ($scope) {
$scope.main = [{"ngmail": "a.vanhala@evil.com", "pass": "thor", "cpass": "thor"}];
$scope.add = function ($scope) {
$scope.main.push($scope.sf);
};
});
</script>
<div>
<div>
<form name="regform" class="form-horizontal" role="form" style=" margin: auto;" >
<div class="form-group">
<label class="control-label col-sm-2" for="email3">Email:</label>
<div class="col-sm-4">
<input type="email" class="form-control" placeholder="Enter email" id="email3" name="email" ng-model="sf.ngmail" required/>
<span class ="alert" ng-show=" regform.email.$touched && regform.email.$error.required"> Required</span>
<span class ="alert" ng-show=" !regform.email.$error.required && (regform.email.$touched && regform.email.$invalid)"> Invalid Email</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd3">Password:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="pwd3" placeholder="Enter password" ng-model="sf.pass" name="password" required/>
<span class ="alert" ng-show=" regform.password.$touched && regform.password.$error.required"> Required</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd4">Confirm password:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="pwd3" placeholder="Enter password" ng-model="sf.cpass" name="cpassword" required/>
<span class ="alert" ng-show=" regform.cpassword.$touched && regform.cpassword.$error.required"> Required</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" ng-click="add()" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
<br>
<div>
<table border="1">
<thead>
<tr>
<th>Email</th>
<th>password</th>
</tr>
</thead>
<tbody >
<tr ng-repeat="m in main">
<td>{{m.ngmail}}</td>
<td>{{m.pass}}</td>
</tr>
</tbody>
</table>
</div>
</body>
当你在函数参数中使用$scope
时,这会杀死控制器&的$scope
依赖性的存在;创建了一个名为$scope
的新变量。您不需要在函数中添加$scope
,它已经在函数中可用了。
$scope.add = function () {
$scope.main.push($scope.sf);
};
你不需要在函数中传递$scope。
试试这样
$scope.add = function () {
$scope.main.push($scope.sf);
};
您是否尝试过不将作用域传递给函数的push方法
$scope.add= function(){ // no scope here
$scope.main.push($scope.sf);
};
相关文章:
- 我的AngularJS表达式没有'不起作用
- AngularJS指令部分应用的函数don'不起作用
- AngularJS ng include dons'不起作用
- AngularJs和Laravel的Pretty Urls不起作用
- Google Maps API OverlayView()在AngularJS指令中不起作用
- AngularJS ng include won'不知什么原因不起作用
- AngularJS没有'不起作用
- Grunt concat js angularjs 不起作用
- angularjs ng点击运行时标记不起作用
- AngularJS:$on dons'不起作用
- AngularJS-简单的教程不起作用
- 输入类型范围在angularjs重复内不起作用
- 数据绑定在特定情况下不起作用(AngularJS)
- 路由不起作用 AngularJS,只是添加一个哈希
- 在 jsfiddle 中拖放表中的行不起作用 - angularjs
- 提交按钮不起作用 AngularJS
- $location.search() 不起作用 - AngularJs 1.5
- 单击按钮时获取单选按钮值不起作用angularjs
- Ng-repeat不起作用AngularJs
- 提交指令不起作用 AngularJS