title: AngularJS redirect to view after data save
body: <p>After saving data from the employee-maintenance view, I am trying to redirect to the employee-details view. I want to do this within the controller's success method:</p>
  
  <pre><code>$scope.insertEmployee = function (employee) {
      if (employee &amp;&amp; $scope.IsNew) {
          employeeFactory.insertEmployee(employee)
              .success(function (data) {
                  // after a successful save, redirect the user to the details view
                  $location.path('/employee-details/' + employee.EmployeeNumber);
                  if (!$scope.$$phase)
                      $scope.$apply()
              })
              .error(function (error) {
                  $scope.status = 'Unable to save the employee data: ' + error;
              });
      }
      else {
          $scope.status = 'You are missing required information!';
      }
  };
  </code></pre>
  
  <p>Here is my factory:</p>
  
  <pre><code>factory.insertEmployee = function (employee) {
      url = baseAddress + "employee/insert/";
      return $http.post(url, employee);
  };
  </code></pre>
  
  <p>My asp.net webapi controller:</p>
  
  <pre><code>    [Route("api/employee/insert/")]
      public HttpResponseMessage Post(Employee employee)
      {
          HttpResponseMessage response = null;
  
          // check for the employee
          Employee employeeCheck = employeeService.GetEmployeeById(employee.EmployeeNumber);
          if (employeeCheck == null)
          {
              if (ModelState.IsValid)
              {
                  employeeService.CreateEmployee(employee);
                  response = Request.CreateResponse(HttpStatusCode.OK);
              }
              else
              {
                  response = Request.CreateResponse(HttpStatusCode.BadRequest, "There was a problem with saving the data.");
              }
          }
          else
          {
              response = Request.CreateResponse(HttpStatusCode.Conflict, "The item already exists");
          }
          return response;
      }
  </code></pre>
  
  <p>This question appears to have been asked quite often but none of the solutions have worked for me.</p>
  
  <p><strong>Edit:</strong> I used the following instead of $location.path()</p>
  
  <pre><code>window.location.href = 'Index.html#/employee-details/' + employee.EmployeeNumber;
  </code></pre>
  
  <p>which worked, but it also generate an ugly runtime error:</p>
  
  <pre><code>JavaScript runtime error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
  </code></pre>