How to get the current year using typescript in angular6
Try, alert((new Date()).getFullYear());
Try, alert((new Date()).getFullYear());
From the Documentation As with components, you can add as many directive property bindings as you need by stringing them along in the template. Add an input property to HighlightDirective called defaultColor: @Input() defaultColor: string; Markup <p [myHighlight]=”color” defaultColor=”violet”> Highlight me too! </p> Angular knows that the defaultColor binding belongs to the HighlightDirective because you … Read more
Once again the angular team makes things harder for not real reason =( I had this problem and after Googling around fruitlessly I wondered if they had changed relative paths somehow as well as renaming angular-cli.json. A little further up in the file I found the line: Yeah, just change: “../node_modules/jquery/dist/jquery.js”, “../node_modules/tether/dist/js/tether.js”, “../node_modules/bootstrap/dist/js/bootstrap.js” to “./node_modules/jquery/dist/jquery.js”, … Read more
You have to install both bootstrap and JQuery: npm install bootstrap jquery –save Then you will find these files in your node module folder: node_modules/jquery/dist/jquery.min.js node_modules/bootstrap/dist/css/bootstrap.min.css node_modules/bootstrap/dist/js/bootstrap.min.js Then you have to update your angular.json file: In the architect, build section, or even test section if you want to see Bootstrap working as well when testing … Read more
Looking at your error ng:///AppRoutingModule/LoginComponent.html@11:2 I can conclude that you declared LoginComponent in AppRoutingModule but didn’t import MatFormFieldModule there. Either move LoginComponent to the declarations array of AppModule: @NgModule({ declarations: [ AppComponent, LoginComponent ], … }) export class AppModule { } or import MatFormFieldModule or some SharedModule in AppRoutingModule: @NgModule({ declarations: [ LoginComponent, … ], … Read more
You will see in your example url, that once you get the 404 error you can’t make it work, but if you include a hash before the angular-specific url like /#latest it will work. Why stops working when refreshing? your webserver is intercepting the GET request from your browser and is trying to go directly … Read more
Best way to update a child component is: ngOnChanges() ngOnChanges(): “A lifecycle hook that is called when any data-bound property of a directive changes. Define an ngOnChanges() method to handle the changes.” We use this lifecycle hook to respond to changes to our @Input() variables. Example: import { Component, Input, OnChanges } from “@angular/core”; @Component({ … Read more
I ran into the same problem. Turns out the solution is “don’t do it”, as explained in this thread by one of the Angular guys: https://github.com/angular/angular-cli/issues/10170#issuecomment-380673276 It boils down to services being easier to tree shake when they are provided by the root module, as I gather. I’m as disappointed as you are.
You will probably need to tell the service worker to check the server for updates, I usually use a service for this: export class UpdateService { constructor(public updates: SwUpdate) { if (updates.isEnabled) { interval(6 * 60 * 60).subscribe(() => updates.checkForUpdate() .then(() => console.log(‘checking for updates’))); } } public checkForUpdates(): void { this.updates.available.subscribe(event => this.promptUser()); } … Read more
Yes in this case it will be only part of your lazy-loaded module/chunks. When using providedIn: ‘root’ the Angular compiler will figure out the perfect way automatically: The service will be available application wide as a singleton with no need to add it to a module’s providers array (like Angular <= 5). If the service … Read more