在将Event参数从Template传递到Typescript按钮单击事件时,遇到绑定值问题。
请参阅下面的对象,它的绑定但它不能反映到Typescript控制器..
它应该是什么原因?
代码: 获取订单模板
<table class="table table-bordered">
<tr>
<td>ID </td>
<td>Name</td>
<td>Price</td>
<td>Action</td>
</tr>
<tr ng-repeat="order in vm.addNewOrderData track by $index">
<td><label>{{order.orderID}}</label> </td>
<td><label>{{order.orderName}}</label> </td>
<td><label>{{order.orderPrice}}</label> </td>
<td><label> <a href="javascript:void(0);" ng-model="editobj" ng-click="vm.edit('{{order.orderID}}');">Edit</a></label> </td>
</tr>
</table>
下面是GetOrderController.ts
class GetOrderController {
public vm: any;
private scope: any;
public addNewOrderData: any;
public http: any;
public location: any;
constructor($http: any, $scope: any, $location:any) {
this.scope = $scope;
this.scope.vm = this;
this.http = $http;
this.location = $location;
$http.get("/api/SampleApi/GetAllOrder").success(
(data, status) => {
if (data != "null") {
this.addNewOrderData = data;
}
}).error((data, status) => {
this.addNewOrderData = data;
});
}
edit = (id: any): void => {
debugger;
var order = { OrderID: id };
this.http.get("/api/SampleApi/GetOrderById",id
).success(
(data, status) => {
if (data != "null") {
this.location.path('/saveOrder?id=' + order);
}
else {
alert("No order id found!");
}
}).error((data, status) => {
});
}
}
答案 0 :(得分:1)
ng-click
不应该有{{}}
(插值),在得到评估时会传递直接表达。
更改
ng-click="vm.edit('{{order.orderID}}');"
到
ng-click="vm.edit(order.orderID);"