1

I m downloading a file using AngularJS and java from server. Because by Ajax GET request doesn't support downloading a file using jax-rs so I am using an alternative approach for it.

Select the different field from UI, on click submit I want to create a url at app.js and want to assign it's return value to href so that href tag force window to open with a popup to download

<input type="button" onclick="location.href=GetUrl();" value="Submit"/>

function in App.js is

  $scope.GetUrl = function() {
      // do some computation;
      return "url"
  }

Can some one help me?

2 Answers 2

1

Change onclick to ng-click to access scope functions

<input type="button" ng-click="GetUrl();" value="Submit"/>


  $scope.GetUrl = function() {
      // do some computation;
      // here assign the url to location.href
      location.href = url;
  }
Sign up to request clarification or add additional context in comments.

2 Comments

in this case, the HTML would be <input type="button" ng-click="GetUrl()" />
Actually I put it in the code but forgot to mention it in the `` back-quotes. So, it was disappear. Anyway, thanks
0

Change onclick to ng-click. onclick does not know $scope bindings. So, it won't call the function GetUrl.

<input type="button" ng-click="location.href=GetUrl();" value="Submit"/>

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.