为什么我们需要ng-form的ng-model?

时间:2015-11-01 20:35:18

标签: angularjs angularjs-ng-model angularjs-ng-form

为什么我们需要ng-form的ng-model?没有它它就无法正常工作 这是ng book的例子

<form name="forma" ng-submit="cliker()" ng-controller="myCtrl">
  <div ng-repeat="filed in fields" ng-form="ngforma">
        <input  type="text" 
                name="nameOfInput" 
                placeholder="{{filed.placeholder}}"
                ng-model="field.name"
                ng-required="filed.isRequired"/>
    <div ng-show="ngforma.nameOfInput.$dirty && ngforma.nameOfInput.$invalid">Error</div>
    </div>
<button type="submit" ng-disabled="forma.$invalid">Submit All</button>
</form>


</body>

<script>
    angular.module("APP", [])
        .controller("myCtrl", function($scope){
            $scope.fields = [
                {placeholder: "placeholder", isRequired: "true"},
                {placeholder: "placeholder", isRequired: "true"},
                {placeholder: "placeholder", isRequired: "false"}
            ],

            $scope.cliker = function(){
                alert("Yes")
            }

        })  
</script>

它在没有ng-model的情况下工作但是ng-disabled不起作用。我甚至可以在ng-model中加入一些随机文本,这样就可以了。

0 个答案:

没有答案