【问题标题】:angular passing value from to different page when anchor tag is clicked单击锚标记时,角度将值从不同页面传递到不同页面
【发布时间】:2015-11-20 14:28:32
【问题描述】:

我正在使用有角度的单页应用程序并且被击中是特定的地方。索引页由ng-view组成

我从 json 文件中获取值到我的主页中,该主页显示在表格中,并且每个名称都被锚标记覆盖

  <h2 class="text-center">{{message}}</h2>
    <div class="container">

      <table class="table table-striped">

        <tbody>
          <tr ng-repeat = 'row in rows'>
            <td><a href="#about">{{row.name}}<a></td>
            <td>{{ row.phone}}</td>
            <td>{{row.time}} </td>  
          </tr>

        </tbody>
      </table>
    </div>
    <hr />

我们可以观察到第一个表数据包含在锚标记中。

当我点击锚标签时,我希望它重定向到关于页面,我点击的名称应该显示在关于页面中

我的关于页面如下所示

<div class="jumbotron text-center">
        <h5>{{message}}</h5>
     hi {{row.name}}
    </div>

http://plnkr.co/edit/4VT5kr41zJZIphiS7q9L?p=preview

请帮助我从一页到另一页获取数据。

感谢任何帮助

【问题讨论】:

标签: javascript html angularjs url-routing


【解决方案1】:

如果您只需要人名,您可以使用$routeParams 传递它。

在 html 中你可以像这样写链接:

<a href="#about/{{row.name}}">{{row.name}}<a>

然后像这样编辑about 路由:

// route for the about page
            .when('/about/:person', {
                templateUrl : 'pages/about.html',
                controller  : 'aboutController'
            })

并将 $scope.person 变量添加到 about 控制器:

scotchApp.controller('aboutController', function($scope, $routeParams) {
        $scope.message = 'Clicked person name from home page should be dispalyed here';
        $scope.person = $routeParams.person;
    });

最后,about.html 视图:

<div class="jumbotron text-center">
    <h5>{{message}}</h5>
 hi {{person}}
</div>

演示:http://plnkr.co/edit/v1mdvmSQ6pE1oxYAdyKi?p=preview

文档:https://docs.angularjs.org/api/ngRoute/service/$routeParams

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2023-04-10
    • 2013-04-13
    相关资源
    最近更新 更多