我有一个ng-click button
,一旦页面加载它就执行Save();
只要在我点击“提交”按钮之前加载页面,它就会将空数据添加到数据库,
为什么它不等待被点击?
我该怎么做才能解决它?
<div class="col-md-2">
<button ng-click="Save()">Submit</button>
</div>
这是我的控制器的一部分:
var App = angular.module("App", ['angularjs-dropdown-multiselect']);
App.controller('autoCompleteCTRL', ['$scope', '$rootScope', 'MyServices', function ($scope, $rootScope, MyServices) {
$scope.Save = function () {
var VCISel = angular.copy($scope.searchText);
var RolesSel = angular.copy($scope.SelectedItems);
MyServices.AddRole(Sel, "adad",RolesSel)
.success(function (data) {
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
};
$scope.Save();
}]);
答案 0 :(得分:3)
在控制器定义的最后,您通过Save
$scope.Save();
函数
答案 1 :(得分:2)
删除$scope.Save();
控制器末尾的autoCompleteCTRL
。
答案 2 :(得分:1)
试试这个
var App = angular.module("App", ['angularjs-dropdown-multiselect']);
App.controller('autoCompleteCTRL', ['$scope', '$rootScope', 'MyServices', function ($scope, $rootScope, MyServices) {
$scope.Save = function () {
var VCISel = angular.copy($scope.searchText);
var RolesSel = angular.copy($scope.SelectedItems);
MyServices.AddRole(Sel, "adad",RolesSel)
.success(function (data) {
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
};
}]);