Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEST ANGULAR #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions test-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BehaviorSubject, catchError, map, of, tap, retry } from 'rxjs';
* Body debe estar todo en minúsculas
* Footer debe estar capitalizado
* /
R. OK
* "Show the content of the observables available in the ContentService
* service in the AppComponent component template. Additionally:"
* Title must be all uppercase
Expand All @@ -25,6 +26,7 @@ import { BehaviorSubject, catchError, map, of, tap, retry } from 'rxjs';
* Se necesita que cuando el usuario haga click en el botón "Change Title", asociado al componente ChangeContentComponent,
* actualize el titulo ("title") que se ve en el componente AppComponent
* /
r. Ok
* "When the user clicks on the "Change Title" button, associated to the ChangeContentComponent, it is required to,
* update the title ("title") seen in the AppComponent."
*
Expand All @@ -48,17 +50,17 @@ import { BehaviorSubject, catchError, map, of, tap, retry } from 'rxjs';
<div class="container">
<section>
<div class="card">
<div class="card-title">{{ title }}</div>
<div class="card-title">{{ title | uppercase }}</div>
<br />
<hr />
<br />

<div class="card-body">{{ body }}</div>
<div class="card-body">{{ body | lowercase }}</div>
<br />
<hr />
<br />

<div class="card-footer">{{ footer }}</div>
<div class="card-footer">{{ footer | titlecase }}</div>
</div>
</section>
<change-content></change-content>
Expand All @@ -78,6 +80,11 @@ export class AppComponent {
providedIn: 'root',
})
export class ContentService {

private titleUpdated: BehaviorSubject<string> = new BehaviorSubject(
'Este es el titulo Modificado'
);

private title: BehaviorSubject<string> = new BehaviorSubject(
'Este es el titulo'
);
Expand All @@ -89,10 +96,15 @@ export class ContentService {
);

private title$ = this.title.asObservable();
private titleUpdated$ = this.titleUpdated.asObservable();
private body$ = this.body.asObservable();
private footer$ = this.footer.asObservable();

constructor() {}
constructor() {
this.getTitle();
this.getBody();
this.getFooter();
}

getTitle() {
return this.title$;
Expand All @@ -107,7 +119,7 @@ export class ContentService {
}

changeTitle() {
// Desarrollar el cuerpo del método / Develop the method body
return this.titleUpdated$;
}
}

Expand All @@ -116,10 +128,16 @@ export class ContentService {
template: `
<section>
<div class="card">
<button> Change Title </button>
<button> Call Api </button>
<section> Connection to API Success </section>
<section> Connection to API Failed </section>
<button (click)="changeTitle()"> Change Title </button>
<button (click)="callApi()"> Call Api </button>
<ng-container *ngIf="flag; else #error">
<section> Connection to API Success </section>
</ng-container>

</ng-content #error>
<section> Connection to API Failed </section>
</ng-content>

</div>
</section>
`,
Expand All @@ -128,6 +146,7 @@ export class ChangeContentComponent {
newTitle = 'Este es el titulo modificado por otro componente';
hasError = false;
hasContent = false;
flag = false;

constructor( private service: GetContentService) {}

Expand All @@ -136,7 +155,16 @@ export class ChangeContentComponent {
}

callApi(){
// Desarrollar el cuerpo del método / Develop the method body

this.service.getContent()
.subscribe(
(res: any) => {
this.flag = true;
},
(error) => {
this.flag = false;
}
);
}
}

Expand Down