错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ clienttask / clienttaskadd”

时间:2019-07-11 15:20:08

标签: angular

所以我的问题是我无法访问路径/clienttask/clienttaskadd

1。路线

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { Router } from '@angular/router';
import { ClientTaskAdd } from './clienttask/clienttaskadd.component';

const routes: Routes = [
  {
    path: 'app-root', component:AppComponent,
     children: [
    {path: 'clienttaskadd', component: ClientTaskAdd},

  ],
}
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

2。 app.component.ts

import { Component } from '@angular/core';
import { ClientComponent } from './client/clientlist.component';
import { ClientTaskComponent } from './clienttask/clienttask.component';
import { Router } from '@angular/router';
import {ClientTaskAdd} from './clienttask/clienttaskadd.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'frontend';
}

3。 clienttask.component.ts

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
//import { ToastrService } from 'ngx-toastr';
import { ClientTaskService } from './../service/clienttask.service';
import { ActivatedRoute } from '@angular/router';

@Component({
    selector: 'clienttaskadd',
    templateUrl: './clienttaskadd.component.html',
    styles: []
})

export class ClientTaskAdd implements OnInit{

    constructor(public service: ClientTaskService){ }

    public response: {dbPath: ''};
    public uploadFinished = (event) => {
      this.response = event;
    };

    ngOnInit() {
      this.service.formModelReport.reset();

    }

   /* onSubmit() {
      this.service.formModelReport.value.FileUrl = this.response.dbPath
      this.service.AddReport().subscribe(
        (res: any) => {
          if (res.succeeded) { 
            this.service.formModelReport.reset();
            this.toastr.success('ثبت نام شد');
          } 
        },
        err => {
          console.log(err);
        }
      );
    }*/

    onSubmit() {
      this.service.formModelReport.value.FileUrl = this.response.dbPath
      this.service.AddReport().subscribe(
        (res: any) => {
          if (res) {
            this.service.formModelReport.reset();
            console.log('true')
            //this.toastr.success( 'ثبت گزارش انجام شد');
          } else {
            res.errors.forEach(element => {
              switch (element.code) {
                case 'DuplicateUserName':
                 // this.toastr.error('خطای رخ داده است','ثبت گزارش نشد');
                  break;

                default:
               // this.toastr.error(element.description,'ثبت نام انجام نشد');
                  break;
              }
            });
          }
        },
        err => {
          console.log(err);
        }
      );
    }
   }

0 个答案:

没有答案