使用angularjs更新一条记录

update a record using angularjs

本文关键字:记录 一条 更新 angularjs 使用      更新时间:2023-09-26

我正在使用angularjs创建一个web应用程序在C#我有多个记录在我的应用程序我想更新的记录,我创建了web服务和需要的js文件更新我只是想知道我需要如何打印文本框和下拉列表上的上一个值

<input type="text" ng-model="uvenuename" ng-init="uvenuename='{{updateparam.VenueName}}'" value="{{updateparam.VenueName}}" style="margin-left: 5%;" placeholder="Venue Name" text="" height="30" />
<input type="text" ng-model="uvenueadd" ng-init="uvenueadd='{{updateparam.Venueadd}}'" value="{{updateparam.Venueadd}}" style="margin-left: 5%;" placeholder="Venue Address" text="" height="30" />

我做了这样的事情,但如果我想改变一个单一的文本框(let see),我只改变场地名称和更新记录,场地地址显示像{{updateparam.Venueadd}}和我的下拉列表显示我空白

<select ng-model="ulocation">
   <option ng-repeat="k in blocation" value="{{k.jlocation}}">
        {{k.jlocation}}
   </option>
</select>

这是我的下拉菜单,如何克服这些流?

不要使用ng-init和value来维护视图和变量之间的绑定,你应该只使用ng-model来使用AngularJS的双绑定。在ng模型中不使用原始数据类型是有必要的,以便使其正常工作。

<input type="text" ng-model="data.uvenuename" style="margin-left: 5%;" placeholder="Venue Name" text="" height="30" />
<input type="text" ng-model="data.uvenueadd" style="margin-left: 5%;" placeholder="Venue Address" text="" height="30" />

select元素

也是一样
<select ng-model="data.ulocation">
   <option ng-repeat="k in blocation" value="{{k.jlocation}}">
      {{k.jlocation}}
   </option>
</select>

在select标签中添加var data。Ulocation将被更新为选项标签中attr值中的值。

数据变量应该是这样的:

$scope.data = {
    uvenuename: "",
    uvenueadd: "",
    ulocation: ""
}