search

Home  >  Q&A  >  body text

angular.js - AngularJs 里数据无法通过controller改变了

貌似第一次被赋值上去了,然后在 controller 里修改 $scope.XXX 无效了。

大家讲道理大家讲道理2745 days ago585

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-15 16:51:54

    Please use $watch! Please check the documentation for detailed usage, and also see this article, for novices.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:51:54

    $scope is a one-way binding, and ng-model is a two-way binding.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 16:51:54

    Data binding is a major feature of Angular. The data bound to the page is all located at the current level (as well as the parent, grandparent...)Controller$scope下。你可以通过设置$scopeto share data with the template.

    Not sure what your problem is?

    1. If you need one-way binding (from controller to template), you can use ng-bind in the template;
    2. If you need two-way binding (controller->template, template->controller), you can use ng-model in the template.

    Pay attention to the two-way binding to the form input control that it acts on, such as input, selectetc.

    For more information about the working mechanism of AngularJS data binding and the timing of data refresh in the view, you can refer to this blog:

    http://harttle.github.io/2015/06/06/angular-data-binding-and-digest.ht...

    reply
    0
  • Cancelreply