gpt4 book ai didi

javascript - Angular routeParams不起作用URL正在更改

转载 作者:行者123 更新时间:2023-11-27 23:56:17 25 4
gpt4 key购买 nike

我在HTML中有一个按钮,其中具有正确呈现的数据。

这部分似乎很好

module.js

.when('/tips/:group?', {
templateUrl: 'partials/tips.html',


controller.js

.controller('TipsCtrl',
// code
$scope.groupid = $routeParams.group;


HTML:

<a href="#/tips/comments/{{ tip.id }}?groupid={{ groupid }}" c class="btn-yellow">Add / View Comments</a>


网址:

<a href="#/tips/comments/10274?groupid=5" class="btn-yellow">Add / View Comments</a>




无效的部分

module.js

.when('/tips/comments/:group?:groupid', {
templateUrl: 'partials/comments.html'


controller.js

.controller('TipCommentsCtrl',
$scope.groupid = $routeParams.group;
$scope.detailFrame = $sce.trustAsResourceUrl("http://localhost:17308/Home/AddComment/" + group);


单击按钮后浏览器中的URL

http://localhost:1337/doc-home/#/tips/comments/1?status=new


为什么会这样呢?

我的网址

<iframe ng-src="http://localhost:17308/Home/AddComment/1" align="middle" width="1000" height="800" frameborder="0" src="http://localhost:17308/Home/AddComment/1">
&lt;p&gt;Your browser does not support iframes.&lt;/p&gt;
</iframe>


如果我更改密码
module.js

浏览器URL更好,但不完全正确。

-->  http://localhost:1337/doc-home/#/tips/comments/10274?status=new 


如果我必须在.module中加入.when时会发生这种情况

.when('/tips/comments/:group?', {
templateUrl: 'partials/comments.html'


但网址不会包含我需要的其他参数

 <iframe ng-src="http://localhost:17308/Home/AddComment/10274" align="middle" width="1000" height="800" frameborder="0" src="http://localhost:17308/Home/AddComment/10274">
&lt;p&gt;Your browser does not support iframes.&lt;/p&gt;
</iframe>


我希望有:

http://localhost:17308/Home/AddComment/10274?groupid=5

最佳答案

确定,此路由应该对您有用:

 module.js -->   Notice the groupid (which you could say anything like 'id'  
.when('/tips/comments/:group?:groupid?', {
templateUrl: 'partials/comments.html'

Next your controller code

controller.js --> Notice that I take a scope param and at to your url

$scope.groupid = $routeParams.groupid;
$scope.detailFrame = $sce.trustAsResourceUrl("http://localhost:17308/Home/AddComment/" + group + "?groupid=" + $scope.groupid);


这应该为您工作。现在,您的IFrame在呈现的变量中将具有正确的网址。

关于javascript - Angular routeParams不起作用URL正在更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32276886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com