1

I'm trying to extend an existing AngularJS application. In the old version, the developer upon pressing a form button Generate report would display a hidden div. Now due to changes in the use-cases it was necessary to put this div within a separate view and dynamically switch to it. So I created a new view in the controller reportDetails.html and it works fine. The hidden view is not shown at first because it requires some values to be set.

The old version did this from the "Generate report" view:

<td class="selection-fields-report">
   <label class="invisible">Dummy</label><br>
   <button class="btn btn-primary" ng-click="generateReport()" ng-disabled="reportData.notReadyForReport">Generate Report</button>
</td>

My new generateReport() implementation attempts to switch to the new view "Report details" and set some DOM elements by id assuming that they are already available ... but they aren't:

$scope.generateReport = function () {
   // ...
   // switch to the report details
   $location.path('/reportDetails');
   // but this 'filterStr' element is not yet available????
   document.getElementById('filterStr').value = "";
   // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error here filterStr doesn't exist ... but it is in the new view reportDetails.html

Do I have to wait for the $location.path('/reportDetails'); to finish i.e. is it a synchronous or asynchronous call?

SkyWalker
  • 13,729
  • 18
  • 91
  • 187
  • Changing view is quite complicated operation and async for a lot of reasons, like template resolving, resolving promises in state Resolve, etc. – Petr Averyanov Jan 24 '17 at 10:22
  • @PetrAveryanov and then, what would be the correct way to solve this use-case? – SkyWalker Jan 24 '17 at 11:08
  • http://stackoverflow.com/questions/28248236/angular-ui-router-passing-data-between-states-without-url pass initial input value in state param – Petr Averyanov Jan 24 '17 at 12:05

0 Answers0