Malik Kashmiri
Malik Kashmiri

Reputation: 5861

Error occurs while passing parameter in function Angular 2

I am trying to call a function from html and it has one int parameter to pass but when I do this it shows error . I have no clue wher I am doing Wrong. following are the typescript and html code and also the error in the image

Component

@Component({
    selector: 'approval',
    templateUrl: '../app/layouts/approval.html'
})
export class ApprovalComponent {
    private _data: Observable<any[]>;

    constructor(public http: Http) {
        this.getAllUser();

    }

    approvalPendingRequest(id) {

        
        var result = this.http.get('https://localhost:44300/api/apis/GetSubscriptionById/'+ id)
            .subscribe(
            data => this._data = data.json(),
            err => this.logError(err),
            () => console.log('getsubscription api call')
            );

        alert(result);


    }
}

Html

<h1>Pending Approvals </h1>
<link href="../../Content/bootstrap.css" rel="stylesheet" />
<link href="../../Content/bootstrap-theme.min.css" rel="stylesheet" />
<div class="container">
    <div class="row">
        <div class="col-offset-md-10">
            <button type="button" class="btn-u  pull-center" data-toggle="modal" data-target="#myModal">Invite User</button>
        </div>

    </div>
    <div class="row">
        <div class="col-md-8">
            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>Account Manager</th>
                            <th>Subscription</th>
                            <th>Created By</th>
                            <th>Pending</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let user of _data">
                            <th>{{user.AccountManagerId}}</th>
                            <th>{{user.SubscriptionId}}</th>
                            <th>{{user.CreatedBy}}</th>
                            <th>
                                <button type="button" class="btn btn-xs btn-danger" (click)="approvalPendingRequest({{user.SubscriptionId}})">
                                    <span class="glyphicon glyphicon-send"></span>&nbsp;
                                </button>
                            
                           </th>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Add New User</h4>
            </div>
            <div class="modal-body">
                <form (submit)='inviteUser()'>
                    <div class="form-group">
                        <label for="name">Name</label>
                        <input type="text" class="form-control" required
                                name="name">
                    </div>
                    <div class="form-group">
                        <label for="alterEgo">Email</label>
                        <input type="email" class="form-control" required
                                name="alterEgo">
                    </div>
                    <div class="form-group">
                        <label for="power">Partner</label>
                        <select class="form-control" 
                                 name="power">
                            <option *ngFor="let p of powers" [value]="p">{{p}}</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-default" data-dismiss="myModal">Invite</button>
                </form>
            </div>

        </div>

    </div>
</div>

image

enter image description here

Upvotes: 0

Views: 293

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202326

Use this rather:

(click)="approvalPendingRequest(user.SubscriptionId)">

You don't need {{...}} here since you are still in an expression executed when the click event occurs.

Upvotes: 2

Related Questions