如何更新Angular2新的路由器查询字符串参数

时间:2016-05-12 20:43:03

标签: angular angular2-routing

在我的组件中,我有一张谷歌地图。如果用户更改了地图的中心,我会更改我的URL并在URL中添加新的中心lat-long,以便用户可以将其作为链接发送。像这样的东西: http://myurl.com/map?center=lat!long

我使用RC1的新路由器

3 个答案:

答案 0 :(得分:2)

现在正确的语法应该是

<body>
    <form>
        // some text inputs

        // where i'd like the drop down to go
        <?php makeList(parameter1, parameter2); ?>

        // submit button
    </form>

<?php
    // connect to database

    function makeList(arg1, arg2) {
        echo '<select>';

        while ($row = mysqli_fetch_array($result)){
            echo "<option">;
            echo $row[$column];
            echo "</option>";

        echo '</select>';
    }
</body>

Doc at Angular.io

答案 1 :(得分:1)

路线

const appRoutes: Routes = [
{ path: 'map/:id', component: mapComponent }]; //id is optional

导航路线

this.router.navigate(['map', '1', { 'center': 'taiwan'  }]);

uri将是这样的:

http://localhost:4200/map/1;center=taiwan

地图组件

import {Router, ActivatedRoute} from '@angular/router';
export class mapComponent implements OnInit {
    constructor(
        private route: ActivatedRoute) {
    }    
    ngOnInit() {
        //Get route parameter
        this.route.params.subscribe(params => {
            let custIdValue = params['id'];
            let centerValue = params['center'];
            //Do somthing...
        });
    }
}

参考:Angular Doc

答案 2 :(得分:0)

您可以使用:

<?php

Class studdetails { 
    public $id; 
    public $name; 
    public $roll;
}

$details = new studdetails();
$details->id = $sid;
$details->name = $sname;
$details->roll = $sroll;

?>