AngularJs按钮失去作用域
AngularJs button loses scope
我的页面上的一个按钮出现$scope问题。页面上有一个ui网格。当单击"添加新记录"按钮时,它会隐藏网格并显示允许用户输入新记录的div。一旦用户单击"保存"按钮保存他们输入的信息,屏幕就会返回到原始状态,显示网格,隐藏其他div。问题是我再也不能点击"添加新"按钮了,因为它已经失去了$scope。
这是我的HTML:
<div ng-app="myModule" ng-controller="OperatorCtrl">
<div class="panel panel-primary">
<div class="panel-heading">Business Unit Administration</div>
<div class="panel-body">
<div ng-hide="noView">
@Html.Label("Edit a Business Unit belo0w to assign Users and Contractors")
<div>
<div ui-grid="gridOptions" class="grid" ng-style="{height: (gridOptions.data.length*30)+32+'px'}" ui-grid-auto-resize></div>
</div>
<div class="pull-right">
<button type="button" class="btn btn-primary" style="width:100px" ng-click="addNew()">Add New</button>
</div>
</div>
<div ng-show="noView">
<form name="AddBusinessUnitForm">
<table style="width:100%">
<thead>
<tr>
<th>Business Unit Name</th>
<th>Operator System ID</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" style="width:200px" ng-model="form.vchDescription" /></td>
<td><input type="text" style="width:300px" ng-model="form.vchOperatorSystemID" /></td>
<td ng-show="addNew"><button type="button" class="btn btn-info btn-sm" ng-click="saveNew()">Save</button></td>
<td>
<button type="button" class="btn btn-primary" style="width:100px" ng-click="return()">Close</button>
</tr>
</tbody>
</table>
</form>
"添加新内容"和"关闭"按钮仅切换"noView"变量以显示和隐藏每个部分。
这是我的Angular:
$scope.addNew = function () {
$scope.noView = true;
};
$scope.saveNew = function () {
$scope.businessUnitName = $scope.form.vchDescription;
operatorService.savenew($scope.form)
.success(function (data) {
$scope.businessUnitID = data;
getUsers($scope.businessUnitID);
$scope.viewTabs = true;
$scope.addNew = false;
});
};
$scope.return = function () {
$scope.noView = false;
};
我是Angular的新手,不知道如何维护按钮的作用域。
非常感谢您的帮助!
在html中,您没有向使用ng-click的函数传递任何内容。因为没有什么可以保存,所以什么都没有保存。我希望这能有所帮助。
相关文章:
- 监视函数从服务返回不起作用,但作用域函数起作用
- 从匿名函数调用mouseover函数时失去作用域
- 尝试重新使用“;这个“;属性,则它将失去作用域
- jQuery 样板 - 失去对“this”作用域的访问权限
- Javascript 局部和全局变量在回调函数中失去作用域
- "这个“;正在失去其父Core的作用域
- AngularJs按钮失去作用域
- Javascript嵌套函数失去作用域
- 为什么JavaScript中的子对象会失去全局作用域
- 匿名函数失去作用域
- 在jQuery AJAX Lightbox中失去作用域
- Angularjs:在两个指令之间失去作用域
- 将JavaScript函数传递给对象内的另一个函数会失去对象变量作用域
- 两个子类继承了超类的属性,并且没有失去作用域
- Javascript Promise/然后失去作用域
- AngularJS:在promise之后的指令中失去作用域
- 在angularjs中,当调用请求的控制器失去作用域时,如何中止http请求
- AngularJS-HTML在ng重复中失去了模板替换的作用域
- 失去变量作用域
- 为什么这个闭包作用域的变量失去了它的值