【问题标题】:Fill value in box on click of a button from a text file单击文本文件中的按钮时在框中填充值
【发布时间】:2017-10-10 06:38:32
【问题描述】:

我有下面的方框来填写信息:

我有下面的代码来创建上面的盒子:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


  <!-- server Location Field  -->

    <div  class="form-group" style="width: 80%; margin-left:10%;" > 
  <span style="position: relative;color:red; left: -10px"><font>*</font> </span>
   <input  maxlength="20" type="text"  class="form-control filled" ng-model="ctrl.form1.serverLocation" placeholder="serverLocation"  name="serverLocation" ng-required="ctrl.form1.date=='Enable'"></input>

  <span ng-show="f2.serverLocation.$dirty && f2.serverLocation.$error.required" style="color: red"> server Location is required</span>
    </div>

我正在尝试创建一个按钮,单击该按钮从 .text 文件中获取要在框中填充的值。例如,对于上面的框,要从文本文件中选择的值是“server_location” .文本文件包含许多字段,例如:

image_location=pqc_11
db_location=xyz_2233
server_location=abc-1122

请帮助了解如何通过单击按钮来填充框。我正在使用 Angular JS 来创建填充框。提前致谢。

【问题讨论】:

  • Check this link的形式从文件中读取数据并简单地绑定到box

标签: javascript html angularjs angular-ui-bootstrap


【解决方案1】:

我认为你应该在 Angular 2 上工作,因为你的生活会更轻松。 在 AngularJS 上只需使用 ngClick https://docs.angularjs.org/api/ng/directive/ngClick

将其添加到您的输入中,然后填写值字段

fillInput() 都可以使用的地方:

1 - ElementRef 访问 DOM 元素并对其进行更改。

2 - ViewChild &lt;input #viewInput type="text" value="{{serverLocation}}"/&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    相关资源
    最近更新 更多