我正在运行一个Spring API服务器和一个Angular-cli服务器来提供我的静态内容.在生产中我们将使用CDN,但是对于开发,前端和后端服务器都在不同端口上的本地盒上运行.Spring服务器提供初始的html页面,然后JS,CSS和html的其余部分来自angular-cli/CDN.
问题是当调用System.import()时,浏览器会抱怨CORS:XMLHttpRequest无法加载http:// localhost:4200/system-config.js.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.zone.js:323错误:错误:加载XHR错误http:// localhost:4200/system-config.js(...)
如何配置angular-cli以设置"Access-Control-Allow-Origin"标题,以便浏览器不会发挥作用.
使用最新的angular-cli,我创建了新项目,一切正常.接下来,我尝试将其集成到Laravel 5.3中.我有这个项目使用systemjs,但我想切换到webpack并利用angular-cli.
问题是在angular-cli.json中我无法指定索引index.php,它只接受HTML.
基本上,我无法使用此设置启动Angular应用程序.
我怎么能克服这个?
我正在尝试将Angular 2应用程序的整个执行移动到Web工作者,但我发现现在所有可用的示例都使用System.js,而我正在尝试使用基于WebPack的项目(用angular-cli构建).
有没有人这样做过,或者对如何使用WebPack有所了解?
下面是我的main.ts引导程序文件:
import './polyfills.ts';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
import {bootstrapWorkerUi} from '@angular/platform-webworker';
bootstrapWorkerUi('/app/loader.js');Run Code Online (Sandbox Code Playgroud)
我loader.js看起来像这样:
import {platformWorkerAppDynamic} from '@angular/platform-webworker-dynamic';
import { AppModule } from './app/';
platformWorkerAppDynamic().bootstrapModule(AppModule);Run Code Online (Sandbox Code Playgroud)
我app.module.ts的声明是@NgModule这样的:
import { NgModule } from '@angular/core';
import {WorkerAppModule} from '@angular/platform-webworker';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
WorkerAppModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule …Run Code Online (Sandbox Code Playgroud)尝试将node-sass-json-importer添加到Angular CLI应用程序中.
我使用1.0.0-beta.17的是CLI 版本,但是还无法使用当前版本来解决1.2这个问题.通过纱线安装后,我不知道应该在应用程序配置中设置它.
有没有人成功地将其整合到他们的应用程 我能找到的唯一答案是使用Webpack的应用程序,而不是Angular CLI.
我正在使用Angular 4 CLI(v.1.0.0)并处理测试我创建了一些使用jasmine来创建间谍的模拟.在IDE中一切看起来都没问题,但是在我收到的终端和错误中写着"找不到名字'茉莉花'".
起初我认为问题是茉莉没有添加到打字中,但我可以看到package.json包含茉莉花类型def的导入,所以我不确定缺少什么.
mocks.ts
export class MockAuthService {
public login: Function = jasmine.createSpy('login');
}
export class MockHttpService {
public delete: Function = jasmine.createSpy('delete');
public get: Function = jasmine.createSpy('get');
public post: Function = jasmine.createSpy('post');
public put: Function = jasmine.createSpy('put');
}
Run Code Online (Sandbox Code Playgroud)
运行ng服务在终端中返回以下错误消息.
C中的错误:/Users/efarley/Desktop/repos/prod/src/app/mocks/mocks.ts(2,23):找不到名字'jasmine'.C:/Users/efarley/Desktop/repos/prod/src/app/mocks/mocks.ts(6,24):找不到名字'jasmine'.C:/Users/efarley/Desktop/repos/prod/src/app/mocks/mocks.ts(7,21):找不到名字'jasmine'.C:/Users/efarley/Desktop/repos/prod/src/app/mocks/mocks.ts(8,22):找不到名字'jasmine'.C:/Users/efarley/Desktop/repos/prod/src/app/mocks/mocks.ts(9,21):找不到名字'jasmine'.webpack:编译失败.
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.spec.json
{
"extends": "../tsconfig.json",
"compilerOptions": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在使用angular2-busyCLI创建的角度项目中使用该库,但是在导入样式表时遇到问题:
<link rel="stylesheet" href="/node_modules/angular2-busy/build/style/busy.css">
浏览器告诉我它找不到文件,即使路径正确.我还检查了文件是否存在,确实存在.当我拿出rel="stylesheet"我没有得到错误,但然后动画不起作用.
这是我试图使用的包,如果有人好奇:https: //www.npmjs.com/package/angular2-busy
我正在测试Highcharts Angular2x Wrapper.首先,我使用Angular CLI(1.6.1)"ng serve"并使用Chrome分析性能时没有任何问题.然后,我尝试使用提前编译来查看它如何影响性能.
所以,使用:
ng serve --aot
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'ChartModule' was called.
Run Code Online (Sandbox Code Playgroud)
现在,我知道aot为模块生成工厂代码,并以某种方式"转换"模板到VanillaJS,这里的事情有点棘手,我无法理解ngc将如何为需要外部库的模块生成工厂代码.
我得到了这个App.Module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ChartModule } from 'angular2-highcharts';
import { AppComponent } from './app.component';
declare var require: any;
export function getHighchartsModule() {
return require('highcharts');
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ChartModule.forRoot(getHighchartsModule) // This causes …Run Code Online (Sandbox Code Playgroud) 角度为6.x的新angular.json文件作为其结构的一部分具有以下内容
"styles": [{
"input": "src/styles.scss"
}],
"scripts": []
},
Run Code Online (Sandbox Code Playgroud)
我当前的angular/cli v1.72与.angular-cli.json相同
"styles": [
"../scss/bootstrap/bootstrap.scss",
"../src/assets/styles/icon8.css",
"styles.scss",
"styles-props.css"
],
"scripts": [
"../node_modules/web-animations-js/web-animations.min.js",
"../node_modules/jquery/dist/jquery.js",
],
Run Code Online (Sandbox Code Playgroud)
如何将v1.7.2转换为v 6.x格式?新格式的"输入"代表什么?
干杯
背景:
ng generate library forms-lib
题:
我正在尝试创建一个库,并使其中的服务可用于需要它们的应用程序,但没有成功.
此代码不起作用:
import { NgModule } from '@angular/core';
import { FormsLibComponent } from './forms-lib.component';
import { FormsLibService } from './forms-lib.service';
@NgModule({
imports: [],
declarations: [FormsLibComponent],
exports: [FormsLibComponent, FormsLibService],
})
export class FormsLibModule {
}
Run Code Online (Sandbox Code Playgroud)
返回错误:
Uncaught Error: Can't export value FormsLibService from FormsLibModule
as it was neither declared nor imported!
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向吗?
谢谢.
我尝试使用ng new angular-6-boilerplateangular-cli最新版本创建一个新的Angular项目,但我不能再这样做了.我正在使用windows终端来创建我的项目,但是我收到了这个错误.
原理图输入不对Schema进行验证:{"name":"angular-6-boilerplate","version":"6.1.2","newProjectRoot":"projects","skipInstall":false,"linkCli": false,"skipGit":false,"commit":null}错误:
Run Code Online (Sandbox Code Playgroud)Data path ".name" should match format "html-selector".
为什么我收到此错误?
angular-cli ×10
angular ×7
javascript ×2
typescript ×2
angular6 ×1
css ×1
highcharts ×1
laravel ×1
node-sass ×1
php ×1
sass ×1
web-worker ×1
webpack ×1