encuadernación angular 2 una vez
En angular 1 podríamos hacer un enlace de una vez de esta manera: {{ ::myFunction() }}
.
En angular 2 esto es lanzar:
EXCEPTION: Template parse errors:
Parser Error: Unexpected token : at column 2 in [{{ ::consent(false, undefined, box) }}] in CookieConsent@5:29 ("ull-right" href="" (click)="consent(true, $event, box)">De acuerdo</a>
<span class="hidden">[ERROR ->]{{ ::consent(false, undefined, box) }}</span>
¿Cómo podemos hacer un enlace de una vez en angular2?
4 answers
ChangeDetectionStrategy.CheckOnce
es la solución para este problema.
Algo de información aquí:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-31 17:35:37
He encontrado la solución para un enlace de tiempo en angular 2 aquí: https://github.com/angular/angular/issues/14033
Creé esta directiva:
import { Directive, TemplateRef, ViewContainerRef, NgZone } from "@angular/core";
@Directive({
selector: '[oneTime]',
})
export class OneTimeDirective {
constructor(template: TemplateRef<any>, container: ViewContainerRef, zone: NgZone) {
zone.runOutsideAngular(() => {
const view = container.createEmbeddedView(template);
setTimeout(() => view.detach());
})
}
}
Y lo usó:
<some-selector *oneTime [somePropertyToOneTimeBinding]="someValueToOneTimeBinding"></some-selector>
Por ejemplo:
<iframe *oneTime [src]="myUrl"></iframe>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-18 19:03:22
Actualmente, no se puede hacer un enlace único con Angular 2. Sin embargo, puede saber cuándo cambia su enlace y restablecer sus entradas.
Angular 2 proporciona un gancho de ciclo de vida de onChanges para el mismo. Necesita implementar la interfaz onChanges para obtener los cambios.
Vea el ejemplo de código a continuación donde, estoy almacenando la propiedad data-bound en una variable privada cuando se llama a OnInit.
export class Footer implements OnInit, OnChanges {
@Input() public name: string;
private privname: string;
constructor() { }
ngOnInit() {
this.privname = this.name;
}
ngOnChanges(changes: { [key: string]: SimpleChange }): void {
if (!changes["name"].isFirstChange()) {
this.name = this.privname;
}
}
}
Más tarde, cuando se producen otros cambios, estoy configurando el valor a su valor antiguo en cambios posteriores.
Este mecanismo funciona como enlace.
Soluciones Alternativas: También puede usar una función setter para capturar los cambios.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-29 20:39:53
ChangeDetectionStrategy.CheckOnce es la solución para este problema.
Esto se ha actualizado a OnPush
ver también comentario en el código:
export declare enum ChangeDetectionStrategy {
/**
* `OnPush` means that the change detector's mode will be set to `CheckOnce` during hydration.
*/
OnPush = 0,
/**
* `Default` means that the change detector's mode will be set to `CheckAlways` during hydration.
*/
Default = 1,
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-07 09:08:43