简体   繁体   English

有ng-disable表达式时如何从控制器启用md-button?

[英]How to enable md-button from controller when it is having ng-disable expression?

I have one md-button in my form and i am setting it with ng-disable expression. 我的表单中有一个md按钮,并用ng-disable表达式设置它。 everything is working fine. 一切正常。 but now I want to enable button on particular condition from controller. 但是现在我想在特定条件下从控制器启用按钮。 I am setting it like this. 我是这样设置的。

vm.verifyMobileForm.$invalid = true; vm.verifyMobileForm。$ invalid = true;

but this didn't work for me. 但这对我不起作用。

this is my element 这是我的要素

<form name="verifyMobileForm" novalidate>
    <md-input-container class="md-block" md-no-float>
        <input type="mobile" id="mobile" ng-value="{{vm.form.mobile}}" 
                name="mobile" ng-model="vm.form.mobile" 
                placeholder="Your Mobile number" 
                ng-pattern="/^[789]\d{9}$/" maxlength="10" required
        />
        <div ng-messages="verifyMobileForm.mobile.$error" role="alert" multiple>
            <div ng-message="required">
                <span >Mobile no. is required</span>
            </div>

        </div>

    </md-input-container>
    <div class="dialog-demo-content" layout="row" layout-wrap layout-margin layout-align="center">
        <md-button type="submit" 
              class="md-raised md-accent submit-button" 
              ng-disabled="verifyMobileForm.$invalid || verifyMobileForm.$pristine" 
              ng-click = "vm.checkMobile($event, document.getElementById('mobile').value)"
        >
            Next
        </md-button>
    </div>
</form>

this is my controller where from i want to set it true 这是我的控制器,我想将其设置为true

(function ()
{
    'use strict';

    angular
        .module('app.pages.auth.verify-mobile')
        .controller('VerifyMobileController', VerifyMobileController);

    /** @ngInject */
    function VerifyMobileController($scope,dataservice,msApi, $state,$mdDialog)
    {
        var vm = this;
        vm.form = {};
        var getMob = dataservice.getData();
        if(getMob){
            vm.form.mobile = getMob[1].mobile;
            vm.verifyMobileForm.$invalid = true;
        }
    }
}();

You say you want to ENABLE the Button on particular condition? 您说要在特定条件下启用按钮吗? So why dont use something like this 那为什么不使用这样的东西

ng-disabled="(verifyMobileForm.$invalid || verifyMobileForm.$pristine) && DISABLEBUTTON" ng-disabled =“(verifyMobileForm。$ invalid || verifyMobileForm。$ pristine)&& DISABLEBUTTON”

... ...

and in controller you can enable button even when form is invalid with 在控制器中,即使表单无效,您也可以启用按钮

$scope.DISABLEBUTTON = false; $ scope.DISABLEBUTTON = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM