What is $route service in AngularJs?

0 votes
Want to know what is the use of $route service and why it is used in javascript?
Feb 10 in Angular by kartik
• 10,760 points
34 views

1 answer to this question.

0 votes

$route is used for deep-linking URLs to controllers and views (HTML partials). It watches $location.url() and tries to map the path to an existing route definition.

Requires the ngRoute module to be installed.

You can define routes through $routeProvider's API.

The $route service is typically used in combined with the ngView directive and the $routeParam service.

Dependencies

  • $location
  • $routeParams

Methods

  • reload();

    Causes $route service to reload the current route even if $location hasn't changed.

    As a result of that, ngView  creates new scope and reinstantiates the controller.

  • updateParams(newParams);

    Causes $route service to update the current URL, replacing current route parameters with those specified in newParams. Provided property names that match the route's path segment definitions will be interpolated into the location's path, while remaining properties will be treated as query params.

Events

  • $routeChangeStart

    Broadcasted before a route change. At this point the route services starts resolving all of the dependencies needed for the route change to occur. Typically this involves fetching the view template as well as any dependencies defined in resolve route property. Once all of the dependencies are resolved $routeChangeSuccess is fired.

    The route change (and the $location change that triggered it) can be prevented by calling preventDefault method of the event. See$rootScope  .

  • $routeChangeSuccess

    Broadcasted after a route change has happened successfully. The resolve dependencies are now available in the current.locals property.

    ngView listens for the directive to instantiate the controller and render the view.

If you want to know more about routing you can check it out the link:: Routing in AngularJS
answered Feb 10 by Niroj
• 21,680 points

Related Questions In Angular

0 votes
1 answer

What is $watch() and it's use in AngularJS?

$watch() function is used to watch the ...READ MORE

answered Feb 3 in Angular by anonymous
• 21,680 points
74 views
0 votes
1 answer

What is $parse in Angularjs

Before we jump into the topic you ...READ MORE

answered Feb 4 in Angular by Niroj
• 21,680 points
129 views
0 votes
1 answer

What is so different about interpolate in AngularJS?

hii @kartik, In order to know about what ...READ MORE

answered Feb 4 in Angular by Niroj
• 21,680 points
75 views
0 votes
1 answer

What is Scope Parameter in AngularJS?

Hey @kartik, Scope Parameter is a collection of ...READ MORE

answered Feb 5 in Angular by Niroj
• 21,680 points
50 views
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17 in Web Development by anonymous
• 10,760 points
47 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20 in Web Development by Niroj
• 21,680 points

edited Jan 21 by Niroj 67 views
+1 vote
1 answer

What are pseudo class in css??

Hey, The state of an element is controlled  by ...READ MORE

answered Jan 20 in Web Development by Niroj
• 21,680 points

edited Jan 21 by Niroj 49 views
0 votes
1 answer

What are the $route service Events provide in AngularJs?

hey, $route is used for deep-linking URLs to controllers ...READ MORE

answered Feb 10 in Angular by Niroj
• 21,680 points
35 views
0 votes
1 answer

What is the service that is used to configure the UI-Router and ngRoute in AngularJs?

Routing comes into play whenever you want ...READ MORE

answered Feb 11 in Angular by anonymous
• 21,680 points
25 views