Mikyas TADESSE Mikyas TADESSE - 1 month ago 18
AngularJS Question

can not route with angularjs

Hello everyone My question is how do i change the uri with angular js. In other words when a function is called i would like to change the page.

Here is my angular code

app.controller('meetupsController', ['$scope', '$resource', function ($scope, $resource) {
var Meetup = $resource('/api/meetups');

Meetup.query(function (results) {
$scope.meetups = results;
});

$scope.meetups = []

$scope.createMeetup = function () {
var meetup = new Meetup();
meetup.name = $scope.meetupName;
meetup.$save(function (result) {
$scope.meetups.push(result);
$scope.meetupName = '';
});
}
}]);


I would like to change the page when the function createMeetup is called. 10q in advance

Answer
app.controller('meetupsController', ['$location,$scope', '$resource', function ($location,$scope, $resource) {
  var Meetup = $resource('/api/meetups');

  Meetup.query(function (results) {
    $scope.meetups = results;
  });

  $scope.meetups = []

  $scope.createMeetup = function () {
    var meetup = new Meetup();
    meetup.name = $scope.meetupName;
    meetup.$save(function (result) {
      $scope.meetups.push(result);
      $scope.meetupName = '';
$location.path('/newValue') <!-- it should be the path you want -->

    });
  }
}]); 
Comments