小编Stu*_*ave的帖子

instance [output.propName] .subscribe不是polyfill产生的函数

我遇到了一个奇怪的问题.我已经研究了这个错误,它通常似乎与@Outputor 的使用有关EventEmitter,但在这里并非如此.

如果我有一个特定的polyfill,我的应用程序中会出现以下错误:

TypeError: instance[output.propName].subscribe is not a function
    at createDirectiveInstance (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:12319:71)
    at createViewNodes (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13776:38)
    at callViewAction (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14210:1)
    at execComponentViewsAction (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14119:1)
    at createViewNodes (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13804:1)
    at createRootView (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13665:1)
    at callWithDebugContext (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:15090:26)
    at Object.debugCreateRootView [as createRootView] (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14373:1)
    at ComponentFactory_.webpackJsonp.../../../core/esm5/core.js.ComponentFactory_.create (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:11260:26)
    at initComponent (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/testing.js:1137:1)
Run Code Online (Sandbox Code Playgroud)

polyfill如下:

Object.prototype.clone = function(deep = false) {
    return (deep)
        ? JSON.parse(JSON.stringify(this)) // Deep clone - copies object property values in full.
        : Object.assign({}, this);         // Shallow clone - copies property values (including object references rather …
Run Code Online (Sandbox Code Playgroud)

typescript karma-jasmine angular

18
推荐指数
1
解决办法
6506
查看次数

NG6:库提供的服务未定义

我正在寻找帮助/指针/指导来调试/理解派生类的问题,该派生类在Angular 6项目中扩展了库提供的服务.

我试图将现有的Angular 5.x项目转换为angular.jsonAngular 6项目中的新工作区格式.

我现有的项目包括一个Angular应用程序和一个NgModule提供服务和其他功能的独立共享.共享模块将在多个应用程序中使用,结构如下:

project-root/
    library/
    main-app/
    other-app/
Run Code Online (Sandbox Code Playgroud)

在我现有的NG5代码中,共享库npm link作为TS源文件进入主应用程序(尽管CLI团队明确不推荐,但它适用于我的团队的工作流程).

在NG6应用程序中,library是一个内部的库项目angular.json,如此构建,并通过路径定义拉入项目tsconfig.json.工作区是标准的NG6布局:

workspace-root/
    dist/...
    node_modules/...
    projects/
        library/
            src/lib/...
        main-app/
            src/app/...
        other-app/
    ...
Run Code Online (Sandbox Code Playgroud)

在大多数情况下,库中提供的服务按原样使用,但可以在主应用程序(或其他应用程序)中进行扩展,以提供特定于应用程序的功能.这在Angular 5中工作正常,但在Angular 6中,我在控制台中尝试加载页面时出现以下错误(ng serve运行时):

Object prototype may only be an Object or null

警告发生在这里:

export class FooService extends FooBaseService { // ...
--------------------------------^
Run Code Online (Sandbox Code Playgroud)

当引导进程实例化FooService时,FooBaseService以'undefined'形式出现.

根据研究,这个错误通常与循环依赖问题有关,但我不认为这是正在发生的事情.我在构建库时遇到任何circ-dep警告,或构建主应用程序的任何问题.此外,运行madge -c (链接)在任何一个dist/library或中找不到任何circ-deps dist/main-app.

我对如何继续调试此问题感到困惑.有谁更深入地了解Angular 6如何处理模块提供的服务,他们可能能够指出我正确的方向?

typescript angular angular6 angular-cli-v6

12
推荐指数
1
解决办法
444
查看次数

以编程方式(非声明性)呈现Meteor模板

我正在尝试使用自定义添加到FullCalendar的事件eventRender.我知道我可以直接从我的eventRender方法返回HTML ,但我更愿意以编程方式将事件数据与预定义的Meteor模板(以及相关事件)合并.

以前我可以使用Meteor.render()但功能不再可用.我很熟悉Template.dynamic,但似乎只能以声明方式提供,而且我在这里看到的大部分问题都很陈旧,所以请参阅已弃用的功能.

这就是我想做的事情:

日历 - 事件填充和渲染:

Template.dashboard.rendered = function(){
  $('#calendar').fullCalendar({
    events: function(start, end, timezone, callback) {
      callback(Events.find().fetch()); 
    },

    eventRender: function(event, element) {
      // PROGRAMMATICALLY RENDER TEMPLATE
      // The following does not work - no data is attached 
      return Template.calendarEvent.renderFunction(event);
    }
  });
};
Run Code Online (Sandbox Code Playgroud)

事件模板HTML

<template name="calendarEvent">
  {{title}} 
  <!-- full layout for rendering event here -->
</template>
Run Code Online (Sandbox Code Playgroud)

事件模板JS

Template.calendarEvent.events({
  // define template event handlers
});
Run Code Online (Sandbox Code Playgroud)

fullcalendar meteor

3
推荐指数
1
解决办法
1431
查看次数

Angular 4.3中的单元测试HttpClientModule:来自HttpTestingController.expectOne(url)的未定义返回值

我试图了解如何使用作为新的一部分提供的模拟功能HttpClientModule.我的测试代码几乎完全匹配现有文档中显示的内容.然而,DOC例子是不完整的-例如,至少为import语句TestBadinject丢失.我假设HttpClient@ angular/common/http 也是如此.我的测试代码添加了这些.

此测试失败,因为调用req后最终未定义httpMock.expectOne.我很欣赏为什么会这样.

import { TestBed, inject } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

describe('HttpClientTestingModule', () => {
  beforeEach(() => TestBed.configureTestingModule({
    imports: [ HttpClientTestingModule ],
    providers: [ HttpClient, HttpTestingController]
  }));

  it('expects a GET request', inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
    http
      .get('/data')
      .subscribe(data => expect(data['name']).toEqual('Test Data'));

    const req = httpMock.expectOne('/data');
    expect(req).toBeDefined();
    expect(req.request.method).toEqual('GET');
    req.flush({name: 'Test Data'});
    httpMock.verify(); …
Run Code Online (Sandbox Code Playgroud)

unit-testing angular

3
推荐指数
1
解决办法
3102
查看次数