在离子上使用角度绑定不起作用

时间:2022-11-28 23:01:24

I'm using angular to populate a form, which can be edited. But the edits are not being captured by the scope variables.

我正在使用angular来填充一个可以编辑的表单。但是范围变量没有捕获编辑。

Here's my code:

这是我的代码:

HTML code:

HTML代码:

<div class="list">
  <label class="item item-input">
    <span class="input-label">Name</span>
    <span>{{name}}</span>
  </label>
  <label class="item item-input">
    <span class="input-label">Locality</span>
    <span>{{locality}}</span>
  </label>
  <label class="item item-input">
    <span class="input-label">City</span>
    <span>{{city}}</span>
  </label>
  <label class="item item-input">
    <span class="input-label">Amenities</span>
    <input type="text" placeholder="Amenities" ng-model="amenities">
  </label>
  <label class="item item-input">
    <span class="input-label">Total Rooms</span>
    <input type="text" placeholder="Total Rooms" ng-model="trooms">
  </label>
</div>
<div class="text-center">
  <button class="button button-positive" ng-click="hotelUpdate()">
    Save Edits
  </button>
</div>

hotelUpdate() :

hotelUpdate():

$scope.hotelUpdate = function() {

  var hotel1 = {
    objectId: $state.params.hotelId,
    amenities: $scope.amenities,
    free_rooms: $scope.frooms,
    total_rooms: $scope.trooms
  }
  Backendless.Data.of( "Hotels" ).save(hotel1)
    .then(function(savedObject){
      console.log(savedObject);
    })
    .catch(function(error){
      console.log(error);
    })
}
}

Is there something wrong with the code? On using binding previously the same way, it has worked fine.

代码有问题吗?以前以相同的方式使用绑定,它工作正常。

1 个解决方案

#1


0  

Before the function cal,declare a scope variable $scope.hotel = {},

在函数cal之前,声明一个范围变量$ scope.hotel = {},

In HTML code,change ng-model like ng-model = "hotel.amenities",

在HTML代码中,更改ng-model,如ng-model =“hotel.amenities”,

In controller,change the code to

在控制器中,将代码更改为

  var hotel1 = {
objectId: $state.params.hotelId,
amenities: $scope.hotel.amenities,
free_rooms: $scope.hotel.frooms,
total_rooms: $scope.hotel.trooms

}

}

#1


0  

Before the function cal,declare a scope variable $scope.hotel = {},

在函数cal之前,声明一个范围变量$ scope.hotel = {},

In HTML code,change ng-model like ng-model = "hotel.amenities",

在HTML代码中,更改ng-model,如ng-model =“hotel.amenities”,

In controller,change the code to

在控制器中,将代码更改为

  var hotel1 = {
objectId: $state.params.hotelId,
amenities: $scope.hotel.amenities,
free_rooms: $scope.hotel.frooms,
total_rooms: $scope.hotel.trooms

}

}