我正在使用带有TypeScript的Angular 2.我使用Angular CLI工具创建了这个项目,并尝试使用命令 - "karma start"运行里面的测试用例 - "app.component.spec.ts".此测试用例由Angular CLI本身生成,并且没有变化.当我运行测试用例时,它会给我以下错误 -
C:\Projects\Angular2\TestProject>karma start
21 08 2016 16:18:34.167:WARN [karma]: No captured browser, open http://localhost:9876/
21 08 2016 16:18:34.178:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
21 08 2016 16:18:34.205:INFO [launcher]: Starting browser Chrome
21 08 2016 16:18:36.677:INFO [Chrome 52.0.2743 (Windows 7 0.0.0)]: Connected on socket /#u3qiejjLaOGa5HdGAAAA with id 54026183
Chrome 52.0.2743 (Windows 7 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token import
at C:/Projects/Angular2/TestProject/src/app/app.component.spec.ts:5
Run Code Online (Sandbox Code Playgroud)
请问某人如何解决此问题.
app.component.spec.ts -
/* tslint:disable:no-unused-variable */
/// <reference path="../../typings/globals/jasmine/index.d.ts" /> …Run Code Online (Sandbox Code Playgroud) 我有项目angular-cli
〜根〜/ SRC/typings.json
{
"globalDevDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
},
"globalDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
"google.maps": "registry:dt/google.maps#3.20.0+20160914131659"
}
}
Run Code Online (Sandbox Code Playgroud)
〜根〜/分型/ index.d.ts
/// <reference path="globals/angular-protractor/index.d.ts" />
/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="globals/google.maps/index.d.ts" />
/// <reference path="globals/hammerjs/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/selenium-webdriver/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)
〜根〜/ SRC/tsconfig.json
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types",
"../typings"
],
"files": [ …Run Code Online (Sandbox Code Playgroud) 我有一个我已经建立的应用程序,SW工作正常.我继续开发而没有注意SW ......现在,在为应用程序充电时,没有更多的SW下载(好像应用程序没有注册SW).
我非常沮丧,因为我不知道如何调试/发现该问题的线索.如何跟踪SW registring进程?
更多背景:
"serviceWorker": true 在.angular-cli.jsonServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }) 在我的app.module.ts中ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })在BrowserModule和last之后第一次尝试,第二次尝试)environment.production是true(它)我可以检查别的吗?我忘记了什么吗?
如果不是我最后的两个解决方案是:
我有一个基于角度2构建的遗留代码.这是我在名为users.input.ts的文件上的代码.它编译成功.但是当我尝试构建时,我得到了编译错误.谁能帮助我做我必须做的事情?
输入select.ts
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChange } from '@angular/core';
import { InputSelectSearchComponent } from '../input-select-search/input-select-search.component';
import { InputBase } from '../../classes/input-base';
import { UIStylekitService } from '../../ui-stylekit.service';
export class InputSelect extends InputBase<string> {
controlType = 'select';
options: {value: string, label: string}[] = [];
constructor(options: {} = {}) {
super(options);
this.options = options['options'] || [];
}
}
@Component({
selector: 'input-select',
templateUrl: 'input-select.component.html',
inputs: ['form','input']
})
export class InputSelectComponent extends InputSelectSearchComponent {
constructor(
private __Stylekit: UIStylekitService ) { …Run Code Online (Sandbox Code Playgroud) 我想使用Three.js(@types/three/index)扩展导入到ng6项目中的类型定义,并使用一组将直接附加到相同“名称空间”的函数。类似于:THREE.myFunction()。我不想声明三any来抑制类型检查和linter,并且我想可以包装一个使用JS类/功能扩展三个的香草JS函数,然后再利用typings.d.ts。
首先,我想将THREE.js加载程序导入到我的项目中,这通常定义了一个可扩展的vanilla函数THREE。
我正在尝试将BinaryLoaderng服务导入ng服务,但不确定如何以正确的方式进行操作。
到目前为止,我所做的是:
npm install three --savenpm install @types/three --save-devimport * as THREE from 'three';scripts数组中angular.json
"scripts": [
"./node_modules/three/examples/js/loaders/BinaryLoader.js"
]
Run Code Online (Sandbox Code Playgroud)
到目前为止一切顺利,但是现在我需要创建一个二进制加载器:
import * as THREE from 'three';
// import { BinaryLoader } from 'three';
// import 'three/examples/js/loaders/BinaryLoader';
export class ThreeManagerService {
const loader = new THREE.BinaryLoader();
...
Run Code Online (Sandbox Code Playgroud)
而且我必须找到BinaryLoader以@types/three/index某种方式添加的方法。这样,我应该能够扩展类型定义,以便能够创建新类型THREE.BinaryLoader。可以做这样的事情吗?
我得到的警告是:
警告:./src/app/shared/three-manager.service.ts 24:25-43“在'三个'中找不到导出'BinaryLoader'(导入为'三个') …
我有一个带有两个应用程序的Angular CLI项目。这两个应用程序是相同的,但是一个应用程序包含构建中的所有文件,另一个则需要排除模块。
Angular CLI版本:1.7.4 Angular版本:5.2.10
我将两个应用程序添加到angular-cli.json文件中,每个应用程序都有一个单独的ts-config文件。
"apps": [
{
"name": "app", <---- first app
"root": "src",
"outDir": "/wwwroot",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json", <----first TS config
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
},
{
"name": "admin", <---- second app
"root": "src",
"outDir": "/wwwroot",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": …Run Code Online (Sandbox Code Playgroud) 在Angular和Angular CLI更新到v6之后,我的lint配置每次尝试运行时都会引发以下错误ng lint --type-check:
具有多个目标的Architect命令不能指定替代。'lint'将在以下项目上运行:atlas-fe,atlas-fe-e2e
错误:具有多个目标的Architect命令无法指定替代。'lint'将在以下项目上运行:
att -fe,atlas-fe-e2e at LintCommand.validate(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / architect-command .js:75:23)
位于/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:274:39 位于/ home / nroma的
Generator.next()
/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:7:71
在
__awaiter(/ home / nroma / workspace / atlas / proto-fe / node_modules / @ angular / cli / models / command-runner.js:3:12)
在Object的 validateAndRunCommand(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:273:12)中。(/home/nroma/workspace/atlas/proto-fe/node_modules/@angular/cli/models/command-runner.js:100:26)
在Generator.next()
处已实现(/ home / nroma / workspace / atlas /proto-fe/node_modules/@angular/cli/models/command-runner.js:4:58)
我正在使用节点v9.9.0(npm v6.0.1)。
这是我的package.json …
是否可以将常见样式与配置特定样式结合在一起?还是要具体说明一下,使用多种配置构建应用?
我有一个应用程序,它根据构建期间使用的配置使用不同的材质主题。这是build应用程序部分的angular.json外观:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/my-app",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"scripts": [ ],
"styles": [
// These are the common styles
"src/styles.scss"
],
"assets": [
"src/assets",
"src/favicon.ico"
]
},
"configurations": {
"theme-one": {
"styles": [
"src/styles/themes/material.theme-one.scss"
]
},
"theme-two": {
"styles": [
"src/styles/themes/material.theme-two.scss"
]
}
}
},
Run Code Online (Sandbox Code Playgroud)
?预期行为:
我想添加/合并styles各个配置中styles指定的以及中的指定build:options。例如,使用以下命令:
ng build --configuration theme-one
Run Code Online (Sandbox Code Playgroud)
上面的命令应包含"src/styles.scss"和"src/styles/themes/material.theme-one.scss"。相同theme-two。
?当前行为:
当前行为是,当我指定配置时,该配置中的 …
我有一个大型的(数百个组件)角(5.2.4)应用程序。我升级了以下组件,并能够构建干净的组件,但是所产生的捆绑包尺寸大于v5:
由于已知的JS堆引起悲伤,我们使用如下所示的npm脚本进行构建:
node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --target=production --aot=true --progress=false --env=STAGING
Run Code Online (Sandbox Code Playgroud)
我根据在角度cli中更改的命令将该脚本修改为以下内容:
node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --prod --aot --progress=false --c=USER
Run Code Online (Sandbox Code Playgroud)
升级之前,我们的主捆绑包大小约为9MB。升级后,约为21MB。任何想法或建议来诊断这一点将不胜感激!
我有一些资产(图像,样式)仅在开发(服务时)时需要。这些资产不得包含在生产版本中。在生产中,这些资产由CDN提供。
我需要:
但:
我在SO上解决了10个类似的问题,在github上解决了5个问题,它们都处理排除文件的问题,但是都没有解决我的情况。
angular ×10
angular-cli ×10
angular6 ×3
typescript ×3
angular5 ×1
build-error ×1
karma-runner ×1
lint ×1
rxjs6 ×1
three.js ×1
tsconfig ×1