This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ providedIn: 'root' }) | |
export class UserService { | |
private id = this.store.selectSnapshot<UserStateModel>(UserState).id; | |
constructor(private http: HttpClient, private store: Store) {} | |
public getUser() { | |
return this.http.get(`${environment.apiUrl}/users/${this.id}`); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ providedIn: 'root' }) | |
export class UserService { | |
constructor(private http: HttpClient, private store: Store) {} | |
public getUser() { | |
const { id } = this.store.selectSnapshot<UserStateModel>(UserState); | |
return this.http.get(`${environment.apiUrl}/users/${id}`); | |
} | |
public getLoginHistory() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SelectSnapshot } from '@ngxs-labs/select-snapshot'; | |
@Injectable({ providedIn: 'root' }) | |
export class AuthGuard implements CanActivate { | |
@SelectSnapshot(AuthState) | |
public auth: AuthStateModel; | |
public canActivate(): boolean { | |
return this.auth.isAuthenticated; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ providedIn: 'root' }) | |
export class AuthGuard implements CanActivate { | |
constructor(private store: Store) {} | |
public canActivate(): boolean { | |
const { isAuthenticated } = this.store.selectSnapshot<AuthStateModel>(AuthState); | |
return isAuthenticated; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngComponentOutlet="ButtonComponent"></ng-container> | |
<!-- Compiled template --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"> | |
<!-- Unused `ng-container` --> | |
<ng-container></ng-container> | |
</ng-template> | |
<!-- Much better, no unused `ng-container` --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"></ng-template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
renderElement: p, // reference to the instance of HTMLParagraphElement | |
componentView: undefined, | |
viewContainer: null, | |
template: undefined | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-some-component', | |
template: ` | |
<ng-tempate> | |
<p>Hello world!</p> | |
</ng-tempate> | |
` | |
}) | |
export class SomeComponent {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-some-component', | |
template: ` | |
<ng-template> | |
<p>Hello world!</p> | |
</ng-template> | |
` | |
}) | |
export class SomeComponent {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngComponentOutlet="ButtonComponent"></ng-container> | |
<!-- Скомпилированный шаблон --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"> | |
<!-- Неиспользуемый `ng-container` --> | |
<ng-container></ng-container> | |
</ng-template> | |
<!-- Гораздо лучше, нет неиспользуемого контейнера --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"></ng-template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-template [ngIf]="authorized"> | |
<button>Profile</button> | |
<button>Logout</button> | |
</ng-template> |