On the $state.go () and ui-sref parameters of Angularjs

Source: Internet
Author: User

Last forwarded about Angularjs fallback article, back to use or JS fallback function, directly with history.back (); Implementation function, at that time, by the way $state.go () about the routing jump. This time, the full analysis of the $state.go (), the function.

 Here are the shorthand steps:

 1. Parameters accepted on the target page: $stateProvider. State (' Page2 ', {params: {' data ': null}});  2. Reference:$state. Go(' Page2 ', {data: ' AAA '}); 3. The target page accepts the parameter: after the controller injects $stateparams can obtain ' AAA ' through the $stateparams.data;

1. The difference between ui-sref, $state. Go

  ui-srefGenerally used in<a>...</a>;

<Ui-sref= "Message-list"> Message Center </a>     

  $state.go(‘someState‘)Generally used in the controller inside;

function($scope, $state) {     $state. Go (' login '); });

These two are essentially the same thing, we look at the source code of UI-SREF:

function(e) {    var button = E.which | | E.button;    if (! ( button > 1 | | E.ctrlkey | | E.metakey | | E.shiftkey | | Element.attr (' target 'var transition = $timeout (function//Here we call $state. Go inside of ui-sref<    c14> $state. Go (ref.state, params, options); });    

Ui-sref Last Call or $state.go () method

2. How to pass parameters

  First, you define the accepted parameters on the target page:

  

 Reference, Ui-sref:

  

  $state. Go:

  

Receive parameters,

Inject $stateparams into the controller of the target page, and then "$stateParams. Parameter name" gets

  

Article turned from: http://www.cnblogs.com/jager/p/5293225.html

On the $state.go () and ui-sref parameters of Angularjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.