Angularjs1 pass on the parameters by url, not ui-self.

王佶
2017/06/07 15:37
统计中

Currently, if you are using angularjs router, and use ui-self to link your destination page in html, and you can pass on the parmaters by ui-self. However, if right click and 'open link in new tab', the parameters in ui-self will be missing, and it can't pass on. what we can do?

first let's browse a code:
1. file 1: audience.js

$stateProvider.state('audiencesCreate', {
        url: '/audience/create-audience',
        params: {folder: null, type: null},
        templateUrl: 'templates/audiences/audiences.create.html'
    });

file 2: checkout.html

<div class="col-md-12">
	<ul>
		<li ng-if="audiencePermission.digital">
			<a ui-sref="audiencesCreate({type:'digital'})">Start a New Digital Audience</a>
		</li>
		<li ng-if="audiencePermission.tv">
			<a ui-sref="audiencesCreate({type:'tv'})">Start a New TV Audience</a>
		</li>
		<li ng-if="audiencePermission.firstParty">
			<a ui-sref="audiencesUpload">Start a New Upload (Audience Onboard)</a>
		</li>
		<li>
			<a ng-click="open(audienceID)">View this Distribution</a>
		</li>
		<li>
			<a href ui-sref="audiencesSaved">Browse Saved Audiences</a>
		</li>
	</ul>
</div>

Question: It can't open link in new tab.

Solution: change js code for url with add '?parameter'
The only difference is now we have the parmeter in url when open digital or tv.

$stateProvider.state('audiencesCreate', {
        url: '/audience/create-audience?type?folder',
        params: {folder: null, type: null},
        templateUrl: 'templates/audiences/audiences.create.html'
    });

本文为 王佶 原创

发布在 http://blog.minws.com/angularjs-pass-on-the-parameters-by-url-not-ui-self/

如有转载,请标明来源!

作者信息
姓名:王佶
地址:南通
签名:美好的程序媛
热评文章
最新评论
文章概览