repositories.component.html
<ul class="collection">
<li class="collection-item blue white-text"
[hidden]="repositories.length > 0">
Cargando repositorio...
</li>
<li class="collection-item red white-text"
[hidden]="!repository">
<h2>{{repository.name}}</h2>
<p>{{repository.description}}</p>
</li>
<li class="collection-item" *ngFor="let repo of repositories">
<h3>{{repo.name}}</h3>
<p>{{repo.description}}</p>
</li>
</ul>
repositories.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-repositories',
templateUrl: './repositories.component.html',
styleUrls: ['./repositories.component.css']
})
export class RepositoriesComponent implements OnInit {
repositories : any =[];
repository : IRepository;
constructor() { }
ngOnInit() {
setTimeout(()=>{
this.repository = {name:"Probando",description:"Proyecto demo de Cf y aungular"};
this.repositories = [
{name:"Probando",description:"Proyecto demo de Cf y aungular"},
{name:"Bootstrap",description:"Frontend FrameWork"},
{name:"Angular code for CF",description:"Codigo del curso Ecommerce"},
{name:"Ruby Code",description:"Codigo con ejemplos"}
];
},2000)
}
}
interface IRepository{
name : String,
description : String
}
Consola
EXCEPTION: Error in ./RepositoriesComponent class RepositoriesComponent - inline template:8:8 caused by: Cannot read property 'name' of undefined
ErrorHandler.handleError @ error_handler.js:54
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
error_handler.js:56ORIGINAL EXCEPTION: Cannot read property 'name' of undefined
ErrorHandler.handleError @ error_handler.js:56
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
error_handler.js:59ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:59
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
error_handler.js:60TypeError: Cannot read property 'name' of undefined
at CompiledTemplate.proxyViewClass.View_RepositoriesComponent0.detectChangesInternal (/AppModule/RepositoriesComponent/component.ngfactory.js:171:71)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:72388:14)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72583:44)
at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:72373:18)
at CompiledTemplate.proxyViewClass.View_AppComponent0.detectChangesInternal (/AppModule/AppComponent/component.ngfactory.js:55:19)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:72388:14)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72583:44)
at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:72373:18)
at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.detectChangesInternal (/AppModule/AppComponent/host.ngfactory.js:29:19)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:72388:14)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72583:44)
at ViewRef_.detectChanges (http://localhost:4200/vendor.bundle.js:54662:20)
at http://localhost:4200/vendor.bundle.js:36590:67
at Array.forEach (native)
at ApplicationRef_.tick (http://localhost:4200/vendor.bundle.js:36590:25)
ErrorHandler.handleError @ error_handler.js:60
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
error_handler.js:63ERROR CONTEXT:
ErrorHandler.handleError @ error_handler.js:63
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
error_handler.js:64DebugContext {_view: C…e.proxyViewClass, _nodeIndex: 8, _tplRow: 8, _tplCol: 8}
ErrorHandler.handleError @ error_handler.js:64
(anonymous) @ application_ref.js:261
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:273
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:535
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:264
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:433
zone.js:420 Unhandled Promise rejection: Error in ./RepositoriesComponent class RepositoriesComponent - inline template:8:8 caused by: Cannot read property 'name' of undefined ; Zone: <root> ; Task: Promise.then ; Value: ViewWrappedError {__zone_symbol__error: Error: Error in ./RepositoriesComponent class RepositoriesComponent - inline template:8:8 caused by:…, _nativeError: ZoneAwareError, originalError: TypeError: Cannot read property 'name' of undefined
at CompiledTemplate.proxyViewClass.View_Repo…, context: DebugContext, __zone_symbol__stack: "Error: Error in ./RepositoriesComponent class Repo…(http://localhost:4200/vendor.bundle.js:54662:20)"…} Error: Error in ./RepositoriesComponent class RepositoriesComponent - inline template:8:8 caused by: Cannot read property 'name' of undefined
at ViewWrappedError.ZoneAwareError (http://localhost:4200/polyfills.bundle.js:6691:33)
at ViewWrappedError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:24983:16)
at ViewWrappedError.WrappedError [as constructor] (http://localhost:4200/vendor.bundle.js:25048:16)
at new ViewWrappedError (http://localhost:4200/vendor.bundle.js:53735:16)
at CompiledTemplate.proxyViewClass.DebugAppView._rethrowWithContext (http://localhost:4200/vendor.bundle.js:72613:23)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72586:18)
at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:72373:18)
at CompiledTemplate.proxyViewClass.View_AppComponent0.detectChangesInternal (/AppModule/AppComponent/component.ngfactory.js:55:19)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:72388:14)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72583:44)
at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:72373:18)
at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.detectChangesInternal (/AppModule/AppComponent/host.ngfactory.js:29:19)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:72388:14)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:72583:44)
at ViewRef_.detectChanges (http://localhost:4200/vendor.bundle.js:54662:20)
consoleError @ zone.js:420
_loop_1 @ zone.js:449
drainMicroTaskQueue @ zone.js:453
zone.js:422 ZoneAwareError {__zone_symbol__error: Error: Uncaught (in promise): Error: Error in ./RepositoriesComponent class RepositoriesComponent - …, rejection: ViewWrappedError, promise: ZoneAwarePromise, zone: Zone, task: ZoneTask}