我在 Angular 2 中进行测试时遇到问题。
describe('Spinner Component', () => {
beforeEach(() => TestBed.configureTestingModule({
declarations: [SpinnerComponent]
}).compileComponents());
beforeEach(() => {
fixture = TestBed.createComponent(SpinnerComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
});
it('Should Create a Spinner Component', () => {
fixture.detectChanges();
var compiled = fixture.debugElement.nativeElement;
expect(compiled).toBeTruthy();
});
it('Should not be running', () => {
fixture.detectChanges();
expect(comp.isRunning).toBe(false);
});
});
Run Code Online (Sandbox Code Playgroud)
上面的代码显示测试中的 Spinner 组件“不应该运行”。我不知道是什么原因造成的。我在控制台中收到错误消息(请参见下文)。如代码中所示,我已经在每个之前的第二个实例上创建了组件实例,但它指出在第二个测试用例上运行时它是未定义的。我需要帮助。我真的很感激。提前致谢。
我似乎无法让Packery使用 angular-cli 和 typescript 2.0 使用 Angular 2。我正在使用 Packery 1.4.1 和来自绝对类型的该版本的打字稿定义。
问题是在使用 ng serve 运行项目时找不到对Outlayer的 Packery 引用。
特别是由于以下原因引发了以下异常:
类型错误:无法在 Object.utils.extend 处设置未定义的属性“位置”(在 webpackJsonp.82.module.exports 处评估)
下面是我的项目代码。
来自 angular-cli.json 的脚本部分:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.js"],
Run Code Online (Sandbox Code Playgroud)
我也尝试添加依赖的 js 文件,但抛出的异常是相同的:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.js",
"../node_modules/get-size/get-size.js",
"../node_modules/outlayer/outlayer.js",
"../node_modules/ev-emitter/ev-emitter.js",
"../node_modules/fizzy-ui-utils/utils.js",
"../node_modules/desandro-matches-selector/matches-selector.js"
],
Run Code Online (Sandbox Code Playgroud)
app.component.ts:
import { Component, ViewChild, AfterViewInit } from '@angular/core';
declare var Packery: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit
{
@ViewChild('grid') grid;
private pckry: any;
constructor() {} …Run Code Online (Sandbox Code Playgroud) 这是 debug.log 文件:
[0110/160818:ERROR:tcp_listen_socket.cc(76)] 无法将套接字绑定到 127.0.0.1:6004 [0110/160818:ERROR:node_debugger.cc(86)] 无法启动调试器服务器 [0111/233417:ERRORt_socket_listen:ERROR .cc(76)] 无法将套接字绑定到 127.0.0.1:6004 [0111/233417:ERROR:node_debugger.cc(86)] 无法启动调试器服务器 [0113/120522:ERROR:tcp_listen_socket.cc(76)] 无法将套接字绑定到 127.0.0.1:6004 [0113/120522:ERROR:node_debugger.cc(86)] 无法启动调试器服务器 [0113/122245:ERROR:tcp_listen_socket.cc(76)] 无法将套接字绑定到 127.0.0.1:6000 [0113/122245:ERROR:node_debugger.cc(86)] 无法启动调试器服务器 [0120/171545:ERROR:tcp_listen_socket.cc(76)] 无法将套接字绑定到 127.0.0.1:6004 [0120/171545:ERROR:ERROR:Tcp_listen_socket.cc(76)] .cc(86)] 无法启动调试器服务器 [0207/173408:ERROR:tcp_listen_socket。cc(76)] 无法将套接字绑定到 127.0.0.1:6004 [0207/173408:ERROR:node_debugger.cc(86)] 无法启动调试器服务器
在 vanilla JS 中,您可以通过执行以下操作来模拟输入的键:
testComponent.dispatchEvent(new Event("keyup"))
Run Code Online (Sandbox Code Playgroud)
但是,在 angular-cli 单元测试或控制台中执行此操作不会在我的组件中触发此功能,该功能通过以下方式响应关键事件:
@HostListener('keyup', ['$event'])
onKeyUp(event: KeyboardEvent) {
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我想知道是否有人知道使用 Angular-Cli 激活子资源完整性的可能方法。根据以下链接:GitHub Pull Request这将是一个功能(或未来的功能)。我希望激活它,但它似乎在当前版本上没有激活。是否有另一种方法可以在 Angular-Cli 中使用子资源完整性?
javascript content-security-policy subresource-integrity angular-cli angular
到目前为止,我正在使用angular-cli 1.3.2 版构建一个 angular 4 应用程序。我在文档中读到我们可以在https://github.com/angular/angular-cli/wiki/stories-global-styles使用全局样式和延迟加载。
现在当我运行命令时
ng build --prod -vc -nc --build-optimizer
Run Code Online (Sandbox Code Playgroud)
它为引导程序生成以下输出
块 {bootstrapBundle} bootstrapBundle.cf320d25069acd157990.bundle.css (bootstrapBundle) 96.9 kB {inline} [initial]
根据我的理解,这个 css 应该应用于网站,但是,当我看到该网站时,它没有应用任何引导 css。
现在,如何在站点中使用 bootstrapBundle 或 bootstrap 块?
这是我的angular-cli.json样式配置
"styles": [
"styles.scss"
{
"input": "./assets/smartadmin/bootstrap.scss",
"lazy": true,
"output":"bootstrapBundle"
},
],
Run Code Online (Sandbox Code Playgroud)
请帮忙。
谢谢。
我刚刚将我的 Angular 应用程序升级到版本 5,效果很好。然而,一旦我升级了其他一些东西(比如@angular/cdk、@angular/material、typescript),我就不得不修复升级带来的一堆错误。当我运行ng serve或ng build --prod(JIT 和 AOT 构建)时,一切看起来都很棒——终端中没有任何错误,应用程序构建成功。然后应用程序localhost:4200按预期运行,但应用程序似乎没有启动,浏览器控制台中根本没有打印任何内容。
我可以做些什么来解决问题?我没有任何错误可以查看,我觉得我只需要猜测出了什么问题。
有什么建议?
应用背景:我的应用是使用 ASP.net MVC(.net framework 4.6) 和几个 Angular 4 mini SPA 构建的
SPA 之一使用这种方法来引导组件。简而言之,这个 SPA 可以引导由一个 Angular 应用程序管理的多个组件。
问题只有当 html 视图中存在组件时,我才想在 providers 数组中添加一个提供者(如果这是正确的词,则动态添加)。希望大家帮帮忙?
示例我想在视图中加载/存在{ provide: APP_BASE_HREF, useValue: '/shoppingbasket/my' }时添加到 providers 数组AddProductToShoppingBasketComponent中
代码
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ComponentFactoryResolver, ApplicationRef, Type } from '@angular/core';
import { HTTP_INTERCEPTORS } from "@angular/common/http";
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
//import { APP_BASE_HREF } from "@angular/common";
import { ToastrModule } from "ngx-toastr";
import …Run Code Online (Sandbox Code Playgroud) 我正在使用 angular5 开发一个应用程序,通过 ng-cli 使用服务工作者,但我意识到在第一次加载应用程序外壳后,它不会刷新。使用ng build?构建应用程序后,如何将新文件版本推送到我的应用程序。我可以直接手动重写 sw.js,但是因为它是通过 cli 生成的,所以我不喜欢影响任何我不知道是做什么的。
我整天都在寻找这个答案,但由于服务工作者是 1.6 版 ng-cli 的新成员,我没有找到任何答案。
我什至在 ng-cli 1.6 之前找到了一个与 angular 4 和非官方 Service Workers 实现类似的线程,但我不相信这种方法,因为它不是官方的,所以我想知道你们是否可以帮我找到一种控制外壳安装方式和寻找新版本的方法。
谢谢
service-worker progressive-web-apps angular-cli angular5 angular-service-worker
我正在尝试安装angular cli,但显示我缺少对/ usr / local / lib / node_modules的写访问权,因此,如何在Mac中修复它,我尝试了一下,但可能无法获得确切答案
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR! …Run Code Online (Sandbox Code Playgroud) angular-cli ×10
angular ×8
unit-testing ×2
angular-aot ×1
angular4 ×1
angular5 ×1
javascript ×1
node-modules ×1
node.js ×1
packery ×1
webpack ×1