使用angular not得到对象值单击Typescript事件

时间:2016-12-31 16:49:58

标签: angularjs templates typescript

在将Event参数从Template传递到Typescript按钮单击事件时,遇到绑定值问题。

enter image description here


请参阅下面的对象,它的绑定但它不能反映到Typescript控制器..

看到这里的价值.. enter image description here

它应该是什么原因?

代码: 获取订单模板

<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) => {

        });
    }
}

1 个答案:

答案 0 :(得分:1)

ng-click不应该有{{}}(插值),在得到评估时会传递直接表达。

更改

ng-click="vm.edit('{{order.orderID}}');"

ng-click="vm.edit(order.orderID);"