我首先在Mobile中使用angularJS,因为适配器未接收到参数值,我收到错误
需要知道如何使用function(function($scope.userName, $scope.password)) & parameter(parameters : [$scope.userName, $scope.password])
或$scope
$scope
变量中的参数
app.controller('loginController',function($scope){
$scope.login = function($scope.userName, $scope.password){
$scope.userNameTxt = angular.element('#usrName').val();
$scope.passwordTxt = angular.element('#pass').val();
console.log($scope.userName, $scope.password);
$scope.userName = $scope.userNameTxt;
$scope.password =$scope.passwordTxt;
$scope.loginProcedure = {
procedure : 'login',
adaptor : 'SQL',
parameters : [$scope.userName, $scope.password]
};
WL.Client.invokeProcedure($scope.loginProcedure,{
onSuccess : $scope.loginSuccess,
onFailure : $scope.loginFailure
});
$scope.loginSuccess = function(data)
{
$scope.data = data;
console.log($scope.data);
};
$scope.loginFailure = function()
{
console.log('failed');
};
}
});
答案 0 :(得分:2)
双向绑定
如果您在控制器中使用双向绑定,如下所示
<div ng-controller="loginController">
<form ng-submit="login()">
<input type="text" ng-model="username" placeholder="Username" />
<input type="password" ng-model="password" placeholder="Password" />
<input class="btn-primary" type="submit" value="Login" />
</form>
</div>
然后您可以使用以下内容:
app.controller('loginController',function($scope){
$scope.login = function(){
$scope.loginProcedure = {
procedure : 'login',
adapter : 'SQL',
parameters : [$scope.username, $scope.password]
};
WL.Client.invokeProcedure($scope.loginProcedure,{
onSuccess : $scope.loginSuccess,
onFailure : $scope.loginFailure
});
$scope.loginSuccess = function(data)
{
$scope.data = data;
console.log($scope.data);
};
$scope.loginFailure = function()
{
console.log('failed');
};
}
});
没有约束力:
如果您没有对表单字段使用双向绑定,则可以尝试以下操作:
app.controller('loginController',function($scope){
$scope.login = function(){
var username = angular.element('#usrName').val();
var password = angular.element('#pass').val();
$scope.loginProcedure = {
procedure : 'login',
adapter : 'SQL',
parameters : [username, password]
};
WL.Client.invokeProcedure($scope.loginProcedure,{
onSuccess : $scope.loginSuccess,
onFailure : $scope.loginFailure
});
$scope.loginSuccess = function(data)
{
$scope.data = data;
console.log($scope.data);
};
$scope.loginFailure = function()
{
console.log('failed');
};
}
});