AngularJs can't access form object in controller ($scope)

后端 未结 7 1414
臣服心动
臣服心动 2020-12-07 12:25

I am using bootstrap-ui more specifically modal windows. And I have a form in a modal, what I want is to instantiate form validation object. So basically I am doing this:

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 12:51

    The normal way if ng-controller is a parent of the form element: please remove this line:

    $scope.form = {};
    

    If angular sets the form to your controllers $scope you overwrite it with an empty object.


    As the OP stated that is not the case here. He is using $modal.open, so the controller is not the parent of the form. I don't know a nice solution. But this problem can be hacked:

    ...

    and in your controller:

    $scope.setFormScope= function(scope){
       this.formScope = scope;
    }
    

    and later in your update function:

    $scope.update = function () {
        console.log(this.formScope.form); 
    
    };
    

提交回复
热议问题