在ng-repeat中重复时禁用提交按钮

时间:2016-08-09 14:03:15

标签: angularjs angularjs-ng-repeat ng-repeat

扩展到question如果我有任何重复项,如何禁用提交按钮或使表单无效

获得解决方案:这是我的代码

HTML

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gnat/bin/../libexec/gcc/x86_64-pc-linux-gnu/4.9.4/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../src/configure --enable-languages=ada,c,c++ --enable-dual-exceptions --enable-_cxa_atexit --enable-threads=posix --with-bugurl=URL:mailto:report@adacore.com --disable-nls --without-libiconv-prefix --disable-libstdcxx-pch --disable-libada --enable-checking=release --disable-multilib --with-mpfr=/boron.a/gnatmail/sandbox/gpl-2016/x86_64-linux/mpfr_stable/install --with-gmp=/boron.a/gnatmail/sandbox/gpl-2016/x86_64-linux/gmp_stable/install --with-mpc=/boron.a/gnatmail/sandbox/gpl-2016/x86_64-linux/mpc_stable/install --with-build-time-tools=/boron.a/gnatmail/sandbox/gpl-2016/x86_64-linux/gcc/build/buildtools/bin --prefix=/boron.a/gnatmail/sandbox/gpl-2016/x86_64-linux/gcc/pkg --build=x86_64-pc-linux-gnu
Thread model: posix
gcc version 4.9.4 20160426 (for GNAT GPL 2016 20160515) (GCC) 

$ gcov -v
gcov (GCC) 4.9.4 20160426 (for GNAT GPL 2016 20160515)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.

$ ghdl -v
GHDL 0.34dev (20151126) [Dunoon edition]
Compiled with GNAT Version: GPL 2016 (20160515-49)
mcode code generator
Written by Tristan Gingold.

Copyright (C) 2003 - 2015 Tristan Gingold.
GHDL is free software, covered by the GNU General Public License.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat /proc/version
Linux version 4.4.0-34-generic (buildd@lgw01-20) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) ) #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016

JS

<a href="javascript:void(0);" class="btn btn-primary" ng-disabled="redemptionStep1.$invalid">Submit</a>

1 个答案:

答案 0 :(得分:0)

控制器

中的某个位置
$scope.hasDuplicate = function() {
    var sorted;

    sorted = $scope.csTagGrp[0].csTags.concat().sort(function(a, b) {
      if (a.keys > b.keys) return 1;
      if (a.keys < b.keys) return -1;
      return 0;
    });

    return sorted.some(function(nth, i){

        if(i> 0  && i < sorted.length) {
          return ((nth[i - 1].keys == nth.keys) || (sorted[i + 1].keys == nth.keys));
        }

        return false;

    });

  };

在模板中

<button type="submit" ng-disabled="hasDuplicate()"> Save </button>