角度:编辑用户个人资料时,应用程序导航到主页

梅维尔

我有两个组成部分:家庭和管理员。在主页组件中,我可以创建,删除和编辑帖子。在管理员上,我确实完全一样,但是使用了另一个数据库集合(我正在使用FireBase)。但是我不了解这种行为:当我单击以编辑员工时,路由器导航到家中。在编辑帖子(主页)时,一切看起来都很好。这两个组件的代码实际上是相同的:

管理员

user: Users[];
  show = false;
  employees: Users = {
    id: '',
    userName: '',
    phone: '',
    role: '',
    name: '',
  };

  edit = false;
  employeeToEdit: Users;

  constructor(private userService: UsersService) {

  }

  ngOnInit() {
    this.userService.getUsers().subscribe(data => {
      this.user = data;
      console.log(this.user);
    });
  }

  addEmployee(item: Users) {
    if (this.employees.userName !== "" && this.employees.phone !== "" && this.employees.role !== ""
      && this.employees.name !==  "") {
      this.userService.addUser(this.employees);
    }else{
     this.show = true;
      setTimeout(function () {
        this.show = false;
      }.bind(this), 3000);
    }
    }


  deleteItem(event, item: Users) {
    this.clearStateE();
    this.userService.deleteUser(item);
  }

  editEmployee(event, item: Users) {
    this.edit = true;
    this.employeeToEdit = item;
  }

  updateItem(item: Users) {
    this.userService.updateUser(item);
    this.clearStateE();
  }

  clearStateE() {
    this.edit = false;
    this.employeeToEdit = null;
  }

HTML:

<h1>Employees</h1>
<div class="card">
  <div class="card-content">
    <span class="card-title">Add Item</span>
    <form (ngSubmit)="addEmployee()" class="col s6">
      <div class="row">

        <div class="input-field col s6">
          <input type="text" placeholder="Add Description" [(ngModel)]="employees.userName" name="description">

        </div>
        <div class="input-field col s6">
          <input type="text" placeholder="Add Description" [(ngModel)]="employees.phone" name="description">

        </div>
        <div class="input-field col s6">
          <input type="text" placeholder="Add Description" [(ngModel)]="employees.role" name="description">

        </div>

      <div *ngIf="show" class="alert alert-danger" role="alert">
        All fields are requiered
      </div>
    </form>
  </div>
</div>


<ul *ngFor="let employee of user" class="collection">
  <li class="collection-item"><strong>{{employee.name}}: </strong> {{employee.phone}} <a href="#" class="secondary-content">
<i (click)="editEmployee($event, employee)" class="fa fa-pencil"></i>
<i *ngIf="edit && employeeToEdit.id == employee.id" (click)="clearStateE()" class="fa fa-compress"></i>
    </a>

<div *ngIf="edit && employeeToEdit.id == employee.id">
      <form (ngSubmit)="updateItem(employee)">
        <div class="row">
          <div class="input-field col s6">
            <input type="text" placeholder="Add Title" [(ngModel)]="employee.name" name="title">
          </div>
          <div class="input-field col s6">
            <input type="text" placeholder="Add Description" [(ngModel)]="employee.phone" name="description">
          </div>
          <div class="input-field col s6">
            <input type="text" placeholder="Add Date" [(ngModel)]="employee.userName" name="description">
          </div>
          <input type="submit" value="Update Item" class="btn orange">
          <button (click)="deleteItem($event, employee)" class="btn red">Delete Item</button>
        </div>
      </form>
    </div>

  </li>
</ul>

Routing.ts:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './components/home/home.component';
import { AdminComponent } from './components/admin/admin.component';

const routes: Routes = [
  {
    path: 'admin', component: AdminComponent
  },
  {
    path: '**',
    component: HomeComponent }
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}

在两个组件之间导航时发生的另一件事是,检索到的数据不再存在(仅当我插入另一个组件时才显示列表)。有人可以帮我吗?

编辑:我尝试过这样的事情,但仍然无法正常工作

const routes: Routes = [
  {
    path: "admin",
    component: AdminComponent
  },
  {
    path: "**",
    redirectTo: "home"

  },
  {
    path: "home",
    component: HomeComponent

  }
吉尔斯达夫

<a href="#" class="secondary-content">的“编辑”按钮周围有一个与冲突的按钮(click)实际上,该#链接将重定向到“主页”页面。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何基于uid创建用户个人资料并导航到个人资料页面?

Vue:如何导航到特定用户的个人资料

iOS应用程序可以打开TikTok用户个人资料吗?

Buildfire应用程序无法使用OAuth令牌检索用户个人资料

Web应用程序使用其user_id或uuid显示用户个人资料

用户的whatsapp应用程序如何检测其联系人的个人资料图片的变化?

聊天应用程序的个人资料扫描代码

在 Android 应用程序中保存个人资料图片

如果用户在登录后更改了他的 facebook 个人资料详细信息,如何在我的应用程序中更新 facebook 个人资料?

编辑个人资料用户 Django

无法编辑用户个人资料

在Facebook Graph API中获取Facebook用户个人资料ID,而不是应用程序范围的用户ID

在本机应用中使用委派权限编辑用户个人资料。哪些字段是可编辑的?

我应该允许用户使用管理应用程序来管理其个人资料吗?

Django-facebook。如何通过其他应用程序(而非django-facebook)使用用户个人资料

导航到其他用户的个人资料(laravel 5.2)

如何将新用户重定向到编辑个人资料页面

如何从主要个人资料中的应用程序中获取我的工作资料应用程序的启动意图?

编辑我的个人资料页面不更新用户个人资料

使用FOS用户捆绑包编辑用户个人资料

如何允许用户在Django中编辑其个人资料?

php-编辑用户的个人资料页面

CanCanCan用户可以编辑自己的个人资料

Django允许用户编辑其个人资料

Facebook API-如何通过Facebook API获取Facebook用户的个人资料图片(无需用户“允许”应用程序)

Eclipse(Mars)中缺少“个人资料AS”-“ Java应用程序”

如何创建允许个人资料图片上传/更改的应用程序?

如何在我的应用程序中使用首选项显示个人资料图片

在iOS应用程序中获取某人的Facebook公开个人资料