Tuesday, 15 January 2013

javascript - Angularjs: Understand how work $location -


I'm new to angular and I have to understand some functions. I have to redirect a button click to another page. I need to change this code:

  function vaiAllaFattura (e) {e.preventDefault (); Var dataitam = this.dataItem ($ (e.currentTarget) .clostest ("tr")); Window.location.href = "@ Url.Action (" create "," fatrazion ")" + "/? IdPrestazioneAgenda =" + data item.id; }  

I have to do this in the corner when I click my button, can someone help me? Thanks!

First of all, you can use the ng-click button on your line ID To pass, to avoid using jQuery in your controller to get it (this line should not be in the $ (e.currentTarget) .closest ("tr") controller) .

  & lt; Tr ng-click = "vaiAllaFattura ($ event)" & gt; ... & lt; / Tr & gt;  

Then you should not use window.location , but use the $ location service (see why). Then your last code should look like this:

  $ scope.vaiAllaFattura = function (e) {$ location.path ("@ Url.Action" ("Create", "Fatturazione") " + "/? IdPrestazioneAgenda =" + e.currentTarget.Id);}  

No comments:

Post a Comment