angular6

What is the proper way to use a dependent npm package in angular 6 library project?

余生颓废 提交于 2019-12-03 12:13:16
问题 I'm a little confused as to how im supposed to reference external npm packages in my library angular6 project. We have an internal scss library I'd like to use to style my reusable components in my library. How do i go about importing that? package.json for lib project: { "name": "ikr-lib", "version": "0.0.1", "peerDependencies": { "@angular/common": "^6.0.0-rc.0 || ^6.0.0", "@angular/core": "^6.0.0-rc.0 || ^6.0.0", "document-register-element": "1.8.1" }, "dependencies": { "element.ui": "^1.0

Angular 6. Is it possible to inject service by condition?

£可爱£侵袭症+ 提交于 2019-12-03 12:09:17
In my angular app (with the angular material) I have a filter panel and I want besides select to be able to make autocomplete (user input value and it sends to the back-end, whereby $regexp query we find the match in MongoDB collection). But to do it I need manually inject service into filters component. I didn't find any info on how to do it. I need something like this: if (filters.serviceName) { injector.inject(serviceName); } injector.get(serviceName).find(searchQuery); Is it possible? Thanks. Yes you can inject service dynamically using injector.get() Sample code : import { Component,

Global is not defined at ../node_modules/socket.io-parser/is-buffer.js

断了今生、忘了曾经 提交于 2019-12-03 11:23:20
thanks in advance for helping me out. I'm trying to connect socket in one of my angular components, but in the console of the browser it throws an error saying that global is not defined at Object ../node_modules/socket.io-parser/is-buffer.js This is my home.component.ts import { Component, OnInit } from '@angular/core'; import * as $ from 'jquery'; import * as io from 'socket.io-client'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) export class HomeComponent implements OnInit { constructor() { } ngOnInit() { } } var socket =

How do I turn off source maps for Angular 6 ng test?

允我心安 提交于 2019-12-03 11:17:16
问题 I am trying to turn off sourcemaps for my tests in Angular 6. I know the sourcemaps switch has been removed, e.g., ng test --sourcemaps=false . I have tried modifying my tsconfig file: { "extends": "../tsconfig.json", "compilerOptions": { ... "sourceMap": false }, as referenced by the angular.json test->configuration block: "test": { ... "options": { ... "tsConfig": "src/tsconfig.spec.json", The source maps are still being generated. 回答1: You can use CLI v6.0.8 and above --source-map=false

Angular/RxJS 6: How to prevent duplicate HTTP requests?

随声附和 提交于 2019-12-03 11:16:55
Currently have a scenario where a method within a shared service is used by multiple components. This method makes an HTTP call to an endpoint that will always have the same response and returns an Observable. Is it possible to share the first response with all subscribers to prevent duplicate HTTP requests? Below is a simplified version of the scenario described above: class SharedService { constructor(private http: HttpClient) {} getSomeData(): Observable<any> { return this.http.get<any>('some/endpoint'); } } class Component1 { constructor(private sharedService: SharedService) { this

Angular 6: Multiple configurations (twas environments)

时光怂恿深爱的人放手 提交于 2019-12-03 08:16:36
问题 Trying to get angular-cli to recognise multiple configurations in angular.json C:\_dev\myapp>ng serve --configuration development Configuration 'development' could not be found in project 'myapp'. Error: Configuration 'development' could not be found in project 'myapp'. The snippet being: "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.production.ts" } ], "optimization": true, "outputHashing": "all

MathJax in Angular 6?

我的梦境 提交于 2019-12-03 07:19:06
问题 Unfortunately, very little information on this library. It is not completely clear to me after installation what I need to import into the app.module.ts and whether there is something to import there? I have prescribed the following code in the index.html: <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] } }); </script> <script type="text/javascript" async src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js? config

Angular 6 - can't resolve all parameters for AppComponent

心不动则不痛 提交于 2019-12-03 06:14:33
I am trying to build an application with Angular 6 and I am still setting everything up. But it seems there is something wrong with the dependency injection in my app. It cannot resolve any constructor parameter. They all result in Uncaught Error: Can't resolve all parameters for AppComponent: (?). . Even a custom service results in the same error. Versions (omitted the dependencies that can't have any influence on this) "dependencies": { "@angular/common": "6.0.5", "@angular/compiler": "6.0.5", "@angular/core": "6.0.5", "@angular/forms": "6.0.5", "@angular/http": "6.0.5", "@angular/platform

refreshing the page results in 404 error- Angular 6

﹥>﹥吖頭↗ 提交于 2019-12-03 05:46:13
问题 I am building an application with the help of Angular6 and facing problems in routing. All the routes are working when I click on a particular tab but whenever I refresh the current page, it is throwing 404 error. I have seen many posts regarding this issue on Stack overflow but failed to overcome from this problem. Below is my app.module.ts import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router';

Angular 6 library shared stylesheets

六眼飞鱼酱① 提交于 2019-12-03 05:43:51
问题 How can you setup a index.scss and import global stylesheets for variables, mixins, etc, to an angular 6 library? Angular CLI generates a lib with a root component & component scss, but the styles added or imported to the root component are not available to children components. Which makes sense by default to encapsulate the styles, but I just can't find any information or examples on how to set this up yet. The angular.json "styles": [...] paths that can be used for this with "projectType":