0

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?

2
  • could you share your controller code !! Commented Jul 25, 2013 at 11:06
  • it should be VM.Delete. see my answer Commented Jul 25, 2013 at 11:22

1 Answer 1

6

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.