角routeParams不工作的网址正在发生变化 [英] Angular routeParams not working URL is changing

查看:158
本文介绍了角routeParams不工作的网址正在发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这部分似乎正常工作

module.js

 。当('/提示/:组',{
    templateUrl:'谐音/ tips.html请',

controller.js

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

HTML:

 < A HREF =?#/提示/评论/ {{tip.id}}组ID = {{GROUPID}}C类=BTN-黄>添加/查看评论< / A>

网址:

 < A HREF =#/提示/评论/ 10274组ID = 5?级=BTN-黄>添加/查看评论< / A>


部分不工作

module.js

 。当('/提示/评论/:组:组ID',{
    templateUrl:'谐音/ comments.html

controller.js

  .controller('TipCommentsCtrl',
$ scope.groupid = $ routeParams.group;
$ scope.detailFrame = $ sce.trustAsResourceUrl(HTTP://本地主机:17308 /主页/ AddComment /+组);

网址在浏览器中点击按钮后,

 的http://本地主机:1337 / DOC家庭/#/提示/评论/ 1状态=新

这是怎么回事?

我的网址为我的

 < IFRAME NG-SRC =HTTP://本地主机:17308 /主页/ AddComment / 1ALIGN =中间WIDTH =1000HEIGHT =800FRAMEBORDER =0SRC =HTTP://本地主机:17308 /主页/ AddComment / 1>
        &放大器; LT; P&放大器; GT;您的浏览器并不支援iframe和放大器; LT; / P&放大器; GT;
    < / IFRAME>

如果我改变code IN
module.js

浏览器的网址是更好,而不是完全正确。

   - > HTTP://本地主机:1337 / DOC家庭/#/提示/评论/ 10274状态=新

这会发生,如果我有module.js要。当是

 。当('/提示/评论/?组',{
    templateUrl:'谐音/ comments.html

但URL不会有我需要的附加参数

 < IFRAME NG-SRC =HTTP://本地主机:17308 /主页/ AddComment / 10274ALIGN =中间WIDTH =1000HEIGHT =800FRAMEBORDER =0SRC =HTTP://本地主机:17308 /主页/ AddComment / 10274>
        &放大器; LT; P&放大器; GT;您的浏览器并不支援iframe和放大器; LT; / P&放大器; GT;
    < / IFRAME>

我想有:

 的http://本地主机:17308 /主页/ AddComment / 10274组ID = 5


解决方案

OK该路由应该为你工作,那么:

  module.js  - >注意GROUPID(你可以说像'ID'什么
 。当('/提示/评论/:组:组识别?',{
    templateUrl:'谐音/ comments.html 接下来你的控制器code controller.js - >请注意,我采取了范围参数,并在你的网址  $ scope.groupid = $ routeParams.groupid;
  $ scope.detailFrame = $ sce.trustAsResourceUrl(HTTP://本地主机:17308 /主页/ AddComment /,?组ID =+组+ $ scope.groupid);

这应该为你工作。现在你的IFrame将在被呈现的变量正确的URL。

I have a button in HTML in which it has the correct data rendered.

THIS part seems to work FINE

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>

URL:

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


Part that is NOT working

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 in Browser after clicking button

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

Why is this happening?

My URL for my

<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>

IF I CHANGE THE CODE IN module.js

Browser URL is better , not completely right.

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

This happens if I have to .when in module.js to be

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

But the URL is not going to have the additional parameter that I NEED

 <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>

I want to have:

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

解决方案

Ok This routing should work for you then:

 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);

This should work for you. Now your IFrame will have that correct url in the variable that gets rendered.

这篇关于角routeParams不工作的网址正在发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆