繁体   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