• <tfoot id='OKB8b'></tfoot>

    <i id='OKB8b'><tr id='OKB8b'><dt id='OKB8b'><q id='OKB8b'><span id='OKB8b'><b id='OKB8b'><form id='OKB8b'><ins id='OKB8b'></ins><ul id='OKB8b'></ul><sub id='OKB8b'></sub></form><legend id='OKB8b'></legend><bdo id='OKB8b'><pre id='OKB8b'><center id='OKB8b'></center></pre></bdo></b><th id='OKB8b'></th></span></q></dt></tr></i><div id='OKB8b'><tfoot id='OKB8b'></tfoot><dl id='OKB8b'><fieldset id='OKB8b'></fieldset></dl></div>
  • <small id='OKB8b'></small><noframes id='OKB8b'>

        <bdo id='OKB8b'></bdo><ul id='OKB8b'></ul>
      1. <legend id='OKB8b'><style id='OKB8b'><dir id='OKB8b'><q id='OKB8b'></q></dir></style></legend>

        如何在 Angular.js 中设置元素的值

        时间:2023-09-06

        <small id='MBvhH'></small><noframes id='MBvhH'>

        <tfoot id='MBvhH'></tfoot>

          • <legend id='MBvhH'><style id='MBvhH'><dir id='MBvhH'><q id='MBvhH'></q></dir></style></legend>
            • <bdo id='MBvhH'></bdo><ul id='MBvhH'></ul>
            • <i id='MBvhH'><tr id='MBvhH'><dt id='MBvhH'><q id='MBvhH'><span id='MBvhH'><b id='MBvhH'><form id='MBvhH'><ins id='MBvhH'></ins><ul id='MBvhH'></ul><sub id='MBvhH'></sub></form><legend id='MBvhH'></legend><bdo id='MBvhH'><pre id='MBvhH'><center id='MBvhH'></center></pre></bdo></b><th id='MBvhH'></th></span></q></dt></tr></i><div id='MBvhH'><tfoot id='MBvhH'></tfoot><dl id='MBvhH'><fieldset id='MBvhH'></fieldset></dl></div>

                <tbody id='MBvhH'></tbody>

                1. 本文介绍了如何在 Angular.js 中设置元素的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么我不能在 Angular.js 中这样做:

                  Why can't I do this in Angular.js:

                  document.getElementById('divid').value = 'Change Text to This';
                  

                  什么是正确"(Angular)的做法?

                  And what is the "right" (Angular) way of doing it?

                  推荐答案

                  在 Angular 中,您使用 ng-model 指令来创建模型之间的双向数据绑定(即 JS变量)和视图(即<div>).基本上,这意味着无论何时您更改视图中的数据(例如,通过输入),更改都会反映在您的 JS 变量中.见下文:

                  In Angular you use the ng-model directive in order to create a two-way data binding between your model (i.e. a JS variable) and the view (i.e. the <div>). Basically, this means that whenever you change the data in the view (through an input, for instance), the change will be reflected in your JS variable. See below:

                  HTML:

                  <html ng-app="myApp">
                      <div ng-controller="MyCtrl">
                          <div>{{myVariable}}</div>
                          <input type="text" ng-model="myVariable" />
                      </div>
                  </html>
                  

                  JS:

                  /* App global module */
                  var myApp = angular.module('myApp');
                  
                  /* Define controller to process data from your view */
                  myApp.controller('MyCtrl', function($scope) {
                  
                     $scope.myVariable = "initialValue"; // this is the variable that corresponds to text inserted in your input
                  
                  });
                  

                  在这里,myVariable 将initialValue"作为初始值.对输入的任何进一步更改都将覆盖此变量的值.

                  Here, myVariable will have "initialValue" as an initial value. Any further changes to the input will overwrite the value of this variable.

                  还要注意 {{myVariable}} 将变量数据注入到您的 div 中.当您更改输入中的值时,div 文本也将更改.

                  Also notice that {{myVariable}} injects the variable the data into your div. When you change the value in the input, the div text will be changed as well.

                  这篇关于如何在 Angular.js 中设置元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:VisJS Timeline:在时间轴中排序项目 下一篇:交换 img src 或显示/隐藏多个图像是否更快?

                  相关文章

                        <bdo id='VhlKt'></bdo><ul id='VhlKt'></ul>

                      <small id='VhlKt'></small><noframes id='VhlKt'>

                    1. <tfoot id='VhlKt'></tfoot>
                    2. <i id='VhlKt'><tr id='VhlKt'><dt id='VhlKt'><q id='VhlKt'><span id='VhlKt'><b id='VhlKt'><form id='VhlKt'><ins id='VhlKt'></ins><ul id='VhlKt'></ul><sub id='VhlKt'></sub></form><legend id='VhlKt'></legend><bdo id='VhlKt'><pre id='VhlKt'><center id='VhlKt'></center></pre></bdo></b><th id='VhlKt'></th></span></q></dt></tr></i><div id='VhlKt'><tfoot id='VhlKt'></tfoot><dl id='VhlKt'><fieldset id='VhlKt'></fieldset></dl></div>
                    3. <legend id='VhlKt'><style id='VhlKt'><dir id='VhlKt'><q id='VhlKt'></q></dir></style></legend>