<p>... blah blah blah.</p><p>Enter your survey data into <a href="/persons">the form</a> and click the 'Analyze' button</p><p>blah blah blah...</p>--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
import { Directive, ElementRef, ContentChildren, ViewChildren } from '@angular/core';
import { Router, RouterLink } from '@angular/router'
@Directive({ selector: '[rewriteAnchors]' })
export class rewriteAnchors {
@ViewChildren(RouterLink) AnchorsInView: QueryList<RouterLink>;
@ContentChildren( RouterLink) AnchorsInContent: QueryList<RouterLink>;
constructor(
private el: ElementRef,
private router: Router
) { }
ngAfterViewInit() {
const el = this.el.nativeElement;
//window.el = el;
console.log(this.AnchorsInView, this.AnchorsInContent, el)
if (el) {
// this code only gets run in the browser, as other envs have (akaik) no nativeelement
const links = Array.from(el.querySelectorAll("a"))
.filter(l => !l.hasAttribute('ng-reflect-router-link'))
.map(l => (console.log(l),l))
.forEach(l => l.addEventListener('click', this.reroute(this)))
;
}
}
reroute(me) {
// use the closure to keep a reference to me(this)
return function reroute(ev) {
// might be confusing, but 'this' points to the element
// orignating the click.
ev.preventDefault();
const url = this.getAttribute("href")
me.router.navigateByUrl(url);
};
}
}
Stop all this please I don't want no more of this crap
I have one question what does 'ng-reflect-router-link' do in the code. Not able to understand that line.
regards
Shweta
ngOnInit() {
this._Faqservice.getFaqList();
}
reroute(me) {
// use the closure to keep a reference to me(this)
return function reroute(ev) {
// might be confusing, but 'this' points to the element
// orignating the click.
ev.preventDefault();
const routeattr = this.getAttribute('routeattr');
let routeid = this._Faqservice.getFaqList.id;
if (routeattr === routeid){
console.log("exists");
let routepageid = this._Faqservice.getFaqList.pageId
console.log(routepageid);
}
me.router.navigate(['/answer'], {relativeTo: me.activeRouter}, {
skipLocationChange: true,
});
}
route module file
const appRoutes: Routes = [
{ path: '', redirectTo: 'faqlist', pathMatch: 'full' },
{ path: 'faqlist', component: FaqlistComponent},
{ path: 'answer/:id', component: AnswerComponent }
];
service with method for deferred list
getFaqId(id: any) {
return this.getFaqList().then((obj) => obj.find(faqlist => faqlist.id === id));
}
getFaqList(){
var def = $.Deferred();
setTimeout(function(){
var obj = [
{id:'news', pageid:'1234'},
{id:'2', pageid:'4567' },
{id:'3', pageid:'97646709877' }
]
def.resolve(obj);
}, 100)
return def;
}
Thanks for your help, i can post the code on plunker if you want.
Regards
Shweta