簡體   English   中英

如何在控制器中訪問表格變量?

[英]How to access variables of form in controller?

我正在對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));
                }
            )
       }
        //////////
    }
})();

嘗試初始化變量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));
            }
        )
   }
    //////////
}
})();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM