Reputation: 2487
I need to call function in type script from the view using angular.js. Technologies that i use are angular.js typescript and ASP.Net MVC3.
this is the link in UI.
<div id="left_aside" ng-controller="MyGivingPortfolioController">
<div class="charity_portfolio_tile" ng-repeat="Tile in VM.Tiles.TileContainerEntity" >
<a href="#" ng-click="Delete(Tile.Id)" class="delete_button">delete</a>
</div>
when i click this link it doesnt invoke the method.
Delete = function (Id:number) {
alert("Called " + Id.toString());
}
then i changed this function like below.
Delete(charityID: number) {
var id = charityID;
alert(id.toString());
}
though i changed the code, it didn't work. Actually i don't know the reason for this.
class MyController implements IMyController {
Tiles: TileContainerEntities;
constructor($scope, $http: ng.IHttpService) {
$scope.VM = this;
$http.get("/API/PrivateAPI/Test/1").success((responce) =>{this.BusinessReponseList = responce; });
}
Delete = function (Id:number) {
alert("Called " + Id);
}
//Delete(charityID: number) {
// var id = charityID;
// alert(id.toString());
//}
}
Does anyone know how to do so?
Upvotes: 0
Views: 3431
Reputation: 275847
Modify the href's ng-click to be ng-click="VM.Delete(Tile.Id)"
i.e.:
<div class="charity_portfolio_tile" ng-repeat="Tile in VM.Tiles.TileContainerEntity" >
<a href="#" ng-click="VM.Delete(Tile.Id)" class="delete_button">delete</a>
</div>
Just useful info not directly related to answer: Be aware of scope inheritance : http://youtu.be/WdtVn_8K17E?t=5m34s . An ng-repeat creates a new scope :)
Upvotes: 6