我在span上设置ng-show指令,我想根据响应值从控制器设置表达式值,但我很难在控制器中访问该表达式并将其设置为值true。
这是我的HTML代码
<md-input-container class="md-block" md-no-float>
<input type="mobile" name="mobile" ng-model="vm.form.mobile" placeholder="Mobile"
ng-pattern="/^[789]\d{9}$/" maxlength="10" pattern="[0-9]*" required>
<div ng-messages="loginForm.mobile.$error" role="alert" multiple>
<div ng-message="required">
<span >Mobile is required</span>
</div>
<div ng-message="pattern">
<span >Mobile must be a valid </span>
</div>
<span ng-show="true">Sorry, Mobile no. is not registered.</span>
</div>
</md-input-container>
这是我的控制器
(function ()
{
'use strict';
angular
.module('app.pages.auth.login')
.controller('LoginController', LoginController);
/** @ngInject */
function LoginController(msApi)
{
// Data
var vm = this;
vm.login = login;
// Methods
function login(){
var jsonData = {"mobile":vm.form.mobile};
msApi.request('login.credentials@save',jsonData,
// SUCCESS
function (response)
{
console.log(response.error);
if(response.error == 1){
vm.form.mobileErrorFlag = true;
}
},
// ERROR
function (response)
{
alert(JSON.stringify(response));
}
)
}
//////////
}
})();
答案 0 :(得分:1)
尝试初始化变量 vm.form.mobileErrorFlag = false;
function LoginController(msApi)
{
// Data
var vm = this;
vm.form.mobileErrorFlag = false;
vm.login = login;
// Methods
function login(){
var jsonData = {"mobile":vm.form.mobile};
msApi.request('login.credentials@save',jsonData,
// SUCCESS
function (response)
{
console.log(response.error);
if(response.error == 1){
vm.form.mobileErrorFlag = true;
}
},
// ERROR
function (response)
{
alert(JSON.stringify(response));
}
)
}
//////////
}
})();