问题
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">
<p>Your browser does not support iframes.</p>
</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">
<p>Your browser does not support iframes.</p>
</iframe>
I want to have:
http://localhost:17308/Home/AddComment/10274?groupid=5
回答1:
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.
来源:https://stackoverflow.com/questions/32276886/angular-routeparams-not-working-url-is-changing