Why populating ng-model inside forms should be followed by $scope.$apply?

前端 未结 2 1555
日久生厌
日久生厌 2021-01-28 04:45

I have a form:

2条回答
  •  自闭症患者
    2021-01-28 04:53

    I think your problem is in the form name. You can read more about angular form here https://docs.angularjs.org/api/ng/directive/form. It says:

    If the name attribute is specified, the form controller is published onto the current scope under this name.

    So, different object stored under this name in scope. Try to set different form name, like this:

    
        
    
    

    And in your controller:

    $scope.placeThis = { target: 0 }
    

    Another way to set initial value is using ng-init

提交回复
热议问题