簡體   English   中英

填寫表單后將設置按鈕激活(角度)

[英]Set button active when form is filled (Angular)

我有以下控制器和指令:

app.controller('controlFormulario', ['$scope', function($scope) {
  var cf = this;
  cf.formulario = [];
  cf.formulario.fecha = new Date();

  if(cf.formulario.texto != null && cf.formulario.titulo != null){
    this.formulario.isDisabled = false;
  }
}]);

app.directive('formulario', [function() {
  return {
    restrict: 'E', // C: class, E: element, M: comments, A: attributes
    templateUrl: 'modules/formulario.html',

  };
}]);

這是按鈕的DOM元素,當title和text字段中有一些文本時,我要啟用該元素:

<div class="form-group" ng-init="formCtrl.formulario.isDisabled = true">
  <button class="btn btn-primary" style="height:35px;width:100px;float:right;" id="submit" disabled={{formCtrl.formulario.isDisabled}}>
  Enviar
  </button>
</div>

當前,啟用按鈕的控制器功能根本不起作用。 我已經在公式的主div中實例化了它,並且它可以與數據綁定一起正常工作,但是某種程度上卻無法啟用該按鈕。

我究竟做錯了什么?

使用ng-disabled代替disabled屬性。

<button class="btn btn-primary" style="height:35px;width:100px;float:right;" id="submit" ng-disabled="formCtrl.formulario.isDisabled">

從鏈接的文檔中:

必須使用特殊指令,因為我們不能在disabled屬性內使用插值。

另外,使用$scope將數據公開給視圖,而不是this this是指控制器,而不是視圖可以看到的$scope

使用ng-disabled代替disabled

暫無
暫無

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

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