如何从 ng-repeat 中访问用户名 [英] How to access the username out of a ng-repeat

查看:23
本文介绍了如何从 ng-repeat 中访问用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 ng-repeat 生成的用户列表和来自 db 的数据,效果很好.现在,当您单击用户时,您会看到一个弹出框.我想在这个弹出框中显示所选用户的名称,但我不知道如何访问用户名,因为弹出框中没有发生 ng-repeat.

请注意,我使用有棱角的材料

我的部分 html 代码:

<div id="logo-wrap"><img id="logo" src="assets/images/logo2.png" alt="Zazzle Logo" >

<div id="sidebar" class="md-whiteframe-z4" ng-data-color=""><div style="height: 80px;"></div><div class="userList" id="usrL"><li id="customLI" ng-repeat="user in users" id="userPos" class="active circle md-whiteframe-z2" style="background-color: {{ user.color }} " ng-click="showPopUpDeletionConfirmation($event, user._id);" ng-data-id="{{ user._id }}"><div ng-if="user._id==activeUser" class="wrapperImageCurrentUser" id="marker_active_user">

<p class="initials" id="userValue" style="top: {{ user.top }};"><custom id="user._id"></custom>{{user.initials}}<!-- {{user.email}} --></p><md-tooltip>{{user.name}}</md-tooltip>

<!-- 边栏结束-->

弹出框 (html) 的代码位于文件 dialog1.tmpl 中.此文件只是弹出框的布局,与分享此问题中的代码无关

这是我的用户列表和弹出框的视觉效果 -> https://gyazo.com/694f65c5269cbca910ec>a79c

你不访问弹出窗口中的用户,而是将用户传递给弹出窗口.

您已经在发送用户 ID,只需发送整个用户即可.发送后使用 user.nameuser._id.

I have a list of users generated with ng-repeat and data from db, which works fine. Now when you click on a user, you get a popup box. I would like to display the name of the selected user in this popup box, but I don't know how to access the username because the ng-repeat does not take place in the popup box.

Note that I work with angular material

Part of my html code:

<!-- START SIDEBAR -->
    <div id="logo-wrap">
      <img id="logo" src="assets/images/logo2.png" alt="Zazzle Logo" >
    </div>
    <div id="sidebar" class="md-whiteframe-z4" ng-data-color="">
      <div style="height: 80px;"></div>
      <div class="userList" id="usrL">
        <li id="customLI" ng-repeat="user in users" id="userPos" class="active circular md-whiteframe-z2" style="background-color: {{ user.color }} " ng-click="showPopUpDeletionConfirmation($event, user._id); " ng-data-id="{{ user._id }}">
          <div ng-if="user._id==activeUser" class="wrapperImageCurrentUser" id="marker_active_user"> </div>
          <p class="initials" id="userValue" style="top: {{ user.top }};" >
            <custom id="user._id"></custom>
            {{user.initials}}
            <!-- {{user.email}} -->
          </p>
          <md-tooltip>{{user.name}}</md-tooltip>
        </li>

      </div>
    </div>
    <!-- END SIDEBAR -->

The code for the popup box (html) resides in the file dialog1.tmpl. This file is just the layout of the popup box nothing relevant to share the code in this question

Here is a visual of my user list and popup box -> https://gyazo.com/694f65c5269cbca910ec6989ee5a77c2

解决方案

You don't access the user in the popup, you pass the user to the popup.

You are already sending the users id, just send the entire user. Use user.name and user._id after you've send it.

这篇关于如何从 ng-repeat 中访问用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆