Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法在我的html中迭代数组_Angular_Typescript - Fatal编程技术网

Angular 无法在我的html中迭代数组

Angular 无法在我的html中迭代数组,angular,typescript,Angular,Typescript,我正在尝试为angular7制作一个面包屑组件,但是我无法让我的数组正确地显示在我的HTML中,我想要一些提示,因为我在互联网上找不到它。如果您能帮助我,我对angular还是个新手,想不出更好的方法来制作面包屑组件 我的组件- breadcrumbLists: Array <any> = []; breadcrumburl: Array <any> = []; constructor(private _router: Router) { } ngOnInit() {

我正在尝试为angular7制作一个面包屑组件,但是我无法让我的数组正确地显示在我的HTML中,我想要一些提示,因为我在互联网上找不到它。如果您能帮助我,我对angular还是个新手,想不出更好的方法来制作面包屑组件

我的组件-

breadcrumbLists: Array <any> = [];
breadcrumburl: Array <any> = [];

constructor(private _router: Router) { }

ngOnInit() {
    this.listenrouting();
}

listenrouting(): void {
    let routerUrl: string, routerList: Array < any > ;
    let i;
    let done;
    this._router.events.subscribe((router: any) => {
        routerUrl = router.urlAfterRedirects;
        if (routerUrl && typeof routerUrl === 'string') {
            this.breadcrumbLists.length = 0;
            routerList = routerUrl.slice(1).split('/');
            this.breadcrumbLists = routerList;

            if (done != false) {

                this.breadcrumbLists.forEach(bread => {

                    if (i != null) {
                        this.breadcrumburl.push([{ name: bread }, { url: i + "/" + bread }])
                    } else {
                        this.breadcrumburl.push([{ name: bread }, { url: "/" + bread }])
                    }

                    i = "/" + bread

                });
            }

            console.log("url", this.breadcrumburl)
            console.log(this.breadcrumbLists)
            done = false;
        }
    });
}
面包屑列表:数组=[]; breadcrumburl:Array=[]; 构造函数(专用_路由器:路由器){} 恩戈尼尼特(){ this.listenrouting(); } listenrouting():void{ 让routerUrl:string,routerList:Array; 让我; 放手; 此._router.events.subscribe((路由器:any)=>{ routerUrl=router.urlAfterRedirects; if(routerUrl&&typeof routerUrl=='string'){ this.breadcrumbLists.length=0; routerList=routerUrl.slice(1).split('/'); this.breadcrumbLists=路由列表; 如果(完成!=错误){ this.breadcrumbLists.forEach(bread=>{ 如果(i!=null){ this.breadcrumburl.push([{name:bread},{url:i+“/”+bread}])) }否则{ this.breadcrumburl.push([{name:bread},{url:“/”+bread}])) } i=“/”+面包 }); } log(“url”,this.breadcrumburl) console.log(this.breadcrumbLists) 完成=错误; } }); } 然后是我的HTML-

<nav>
    <div>
        <li *ngFor="let Breadcrumb of breadcrumburl">
            <a routerLink="{{Breadcrumb.url}}">{{Breadcrumb.name}}</a>
        </li>
    </div>
</nav>


{{Breadcrumb.name}

如果我没有错的话,您希望将
breadcrumburl
数组作为-

目前,您在
breadcrumburl

如果我没有错的话,您希望将
breadcrumburl
数组作为-


目前,,你创建了嵌套数组并在
breadcrumburl

Breadcrumb.url
-没有大写字母
B
如果是这样的话,我会尖叫,但不是这样的,这是我的代码中的一个错误,它不是那样工作的,但你的答案很有效,谢谢我尝试了,因为我知道它们嵌套在哪里数组的,但我想我试过了,但我不这么认为,因为现在没有错误
Breadcrumb.url
-没有大写字母
B
,如果是这样的话,我会尖叫,但不是这样的,这是我的代码中的一个错误,它不是那样工作的,但你的答案有效,谢谢我试过了,因为我知道嵌套数组的位置,但我想我试过了,但我不这么认为,因为现在没有错误
this.breadcrumburl.push({name: bread, url: i + "/" + bread});