小编dav*_*688的帖子

Karma:属性没有访问类型 get

我的 Angular 应用程序中的 Karma 测试出错。错误是当我运行测试时:

Failed: Property activePropertyChanged does not have access type get

我正在尝试模拟一个名为ModuleSpecService. 在此服务中有以下 getter:

get activePropertyChanged(): Observable<SpecificationPropertyObject> {
    return this.activePropChangedSubject.asObservable();
}
Run Code Online (Sandbox Code Playgroud)

在我的spec文件中,我像这样模拟它:

spyOnProperty(moduleSpecServiceMock, 'activePropertyChanged', 'get').and.returnValue(of());

// then, in configureTestingModule() I define/mock the service like this:
providers: [{ provide: ModuleSpecService, useValue: moduleSpecServiceMock }]
Run Code Online (Sandbox Code Playgroud)

所以我的服务中显然有一个我想嘲笑的吸气剂。如果我删除带有spyOnProperty()它的行会引发以下错误:

TypeError: this.moduleSpecService.activePropertyChanged.subscribe is not a function

所以我绝对需要模拟。

知道会出什么问题吗?

jasmine karma-runner angular

17
推荐指数
1
解决办法
1万
查看次数

Angular 2:获取授权标题

在我的应用程序(Angular 2/Ionic 2)中,我实现了自己的登录/身份验证.基本上它的工作方式如下:在登录时,PHP后端正在验证用户名和密码.生成令牌,然后将其发送回标题中的前端(授权).后端的响应如下:

HTTP/1.1 200 OK
Host: localhost:8080
Connection: close
X-Powered-By: PHP/5.6.28
Set-Cookie: PHPSESSID=jagagi2le1b8i7r90esr4vmeo6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: application/json
 Authorization: d7b24a1643a61706975213306446aa4e4157d167eaad9aac989067a329c492d3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Content-Length: 301
Run Code Online (Sandbox Code Playgroud)

显然有一个带有令牌的Authorization标头.CORS似乎也可以正确设置,因为我在Allow-Headers标头中看到了Authorization.

但是,当我尝试在Angular 2中获取头时,它总是返回null:

private extractDataAndSetAuthHeader(res: Response) {

    // Set auth header if available.
    // If not available - user is not logged in. Then 
    // we also have to remove …
Run Code Online (Sandbox Code Playgroud)

authentication ionic2 angular

9
推荐指数
2
解决办法
9563
查看次数

@ViewChild返回undefined

出于某种原因,我的Angular 5 App中的@ViewChild不起作用.我在我的组件中定义了这样的:

案例detail.component.html:

<div class="inner-tab-content" #innerTabContent>
    <!-- // more content here -->
</div>
Run Code Online (Sandbox Code Playgroud)

@ViewChild在我的控制器(构造函数之上)实现了这样:

案例detail.component.ts

@ViewChild('innerTabContent') tabContentElement: ElementRef;
Run Code Online (Sandbox Code Playgroud)

我想在组件中访问它: case-detail.component.ts

ngAfterViewInit() {
    console.log("scroll top: " + this.tabContentElement.nativeElement);
}
Run Code Online (Sandbox Code Playgroud)

我已经实现了AfterViewInit界面.正确调用ngAfterViewInit().但是,this.tabContentElement总是如此undefined.

任何帮助是极大的赞赏 :)

viewchild angular

8
推荐指数
4
解决办法
1万
查看次数

从嵌套表单组获取控件

我有一个FormGroup,嵌套在另一个FormGroup中,我想在其中使用get()获得某个控件。

我尝试了以下解决方案,该解决方案不起作用:

formGroup.get('formGroupKey').get('formControlKey');
Run Code Online (Sandbox Code Playgroud)

但这会引发错误。第一个get()有效(并正确返回FormGroup),但是第二个get引发异常(path.split不是函数)

知道我该如何解决吗?

@更新

我现在用这种方式解决了(尽管这不是一个很好的解决方案):

formGroup.get(tab.id)['controls'][segment.id];
Run Code Online (Sandbox Code Playgroud)

angular angular-reactive-forms

5
推荐指数
1
解决办法
3168
查看次数

JSON:@Transient 字段未序列化

我有一个域类 Loan.java 有一个不持久的字段:

@JsonInclude()
@Transient
private LoanRating loanRating;

/* (Public) Getters and setters for that field are available as well */
Run Code Online (Sandbox Code Playgroud)

但是,该字段没有被序列化 - 我在前端没有看到它。我正在和杰克逊一起做序列化。

任何想法我做错了什么?

如果您需要更多信息,请告诉我,我会发布其他代码:)

spring json jackson

4
推荐指数
1
解决办法
1811
查看次数

AbstractControl 类型上不存在属性 addControl

我有一个嵌套的 FormGroup,它看起来像这样:

this.formGroup: FormGroup: {
    // ...
    controls: {
        "GENERAL_AND_PERSONAL_QUESTIONS": { // FormGroup object... }
    }
}
Run Code Online (Sandbox Code Playgroud)

对于顶级 FormGroup,我可以轻松添加如下控件:

this.formGroup.addControl(tab.id, this.formBuilder.group({}));
Run Code Online (Sandbox Code Playgroud)

但是,由于某种原因,我无法向子 formGroup 添加任何控件。我尝试像这样添加它们:

// tab.id = "GENERAL_AND_PERSONAL_QUESTIONS";
this.formGroup.get(tab.id).addControl(segment.id, this.formBuilder.group({}));
Run Code Online (Sandbox Code Playgroud)

但它总是抛出一个编译错误说:

Property 'addControl' does not exist on type 'AbstractControl'.
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏 :)

typescript angular angular-reactive-forms

4
推荐指数
1
解决办法
3166
查看次数

在 Angular 5 应用程序中渲染 PDF

我正在尝试在 Angular 5 应用程序中呈现 PDF。基本上,我发送 GET 请求以获取文件流(没有链接!这在我们的场景中是不可能的)。文件流带有Content-Type: application/pdf.

现在我有两个问题:

首先,响应从服务器返回 200(没关系,但它总是在我的 angular 应用程序中报告错误:

获取 PDF 的方法如下所示:

  fetchPdfAjaxRequest(caseId: string) {
    this.caseListService.getPdfFileStream(caseId)
                        .takeUntil(this.ngUnsubscribe)
                        .subscribe( (res) => {
                          console.log(res);
                        },
                        (error) => {
                          this.errorService.displayError(error.status, error.statusText);
                        });
  }
Run Code Online (Sandbox Code Playgroud)

我的服务方法如下所示:

public getPdfFileStream(caseId: string) {
    const url = this.CASE_API_URL + '/' + caseId + '/pdf';
    let headers = new HttpHeaders();
    headers = headers.set('Accept', 'application/pdf');

    return this.httpClient.get(url, {headers: headers});
  }
Run Code Online (Sandbox Code Playgroud)

然而,即使它以 200 响应,它也会进入错误分支。是不是因为我需要在请求中设置一些额外的标头?

响应正文只是一个巨大的字符串:

// just an excerpt from the "response" tab in Chrome dev …
Run Code Online (Sandbox Code Playgroud)

pdf angular

4
推荐指数
1
解决办法
7864
查看次数

反应式表单:计算 formGroup 中的所有 formControls

我现在已经用反应式形式做了很多工作,并且非常喜欢它的概念。但是,我想知道是否有一种简单的方法来计算 formGroup 中的所有 formControl,或者我是否必须对其进行迭代?

我有一个复杂的嵌套 formGroup 结构,有 6 层或 7 层,这样可以节省我一点时间。

欢迎任何提示:)

angular angular-reactive-forms

4
推荐指数
2
解决办法
6756
查看次数

找到无效的PostCSS插件:[0]

我现在正在努力让我的Spring Boot App再次运行几天......

我想将我的应用程序部署到Heroku,我得到了一个非常奇怪的错误:

Uncaught Error: Module build failed: TypeError: Invalid PostCSS Plugin found: [0]
at C:\Entwicklung\git\Coinlender\node_modules\postcss-load-plugins\lib\plugins.js:32:17
at Array.forEach (native)
at plugins (C:\Entwicklung\git\Coinlender\node_modules\postcss-load-plugins\lib\plugins.js:21:15)
at C:\Entwicklung\git\Coinlender\node_modules\postcss-load-config\index.js:64:18
at C:\Entwicklung\git\Coinlender\node_modules\postcss-load-plugins\lib\plugins.js:32:17
at Array.forEach (native)
at plugins (C:\Entwicklung\git\Coinlender\node_modules\postcss-load-plugins\lib\plugins.js:21:15)
at C:\Entwicklung\git\Coinlender\node_modules\postcss-load-config\index.js:64:18
at Object.module.exports.createDebug.debug.createDebug.default (http://localhost:8080/vendor.dll.js:94862:7)
at __webpack_require__ (http://localhost:8080/vendor.dll.js:21:30)
at Object.module.exports (http://localhost:8080/vendor.dll.js:112728:15)
at __webpack_require__ (http://localhost:8080/vendor.dll.js:21:30)
at Object.defineProperty.value (http://localhost:8080/vendor.dll.js:94506:84)
at __webpack_require__ (http://localhost:8080/vendor.dll.js:21:30)
at Object.24 (http://localhost:8080/app/main.bundle.js:13268:42)
at __webpack_require__ (http://localhost:8080/app/manifest.bundle.js:694:30)
at fn (http://localhost:8080/app/manifest.bundle.js:115:20)
at Object../src/main/webapp/app/app.module.ts (http://localhost:8080/app/main.bundle.js:3641:1)
Run Code Online (Sandbox Code Playgroud)

我用Google搜索并发现我的绑定可能不正确.所以我执行了

npm rebuild node-sass --force
Run Code Online (Sandbox Code Playgroud)

为了正确设置它们.但这没有帮助.从那以后我收到了这个错误.

我还发现提示它与我的postcss.config.js有关,它是空的(它现在已经工作了6周).所以我添加了一些插件.它现在看起来像这样:

module.exports = {
  parser: require('postcss-scss'),
  plugins: …
Run Code Online (Sandbox Code Playgroud)

webpack postcss webpack-2 yarnpkg postcss-loader

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

Spring:多个缓存管理器

我在实现 secong 缓存管理器时遇到了问题。目前我正在使用 EhCache,它工作正常。另外我想实现Java Simple Cache。

我的 CacheConfiguration 看起来像这样:

缓存配置文件

@Configuration
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class })
@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })
public class CacheConfiguration {

private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;

public CacheConfiguration(JHipsterProperties jHipsterProperties) {
    JHipsterProperties.Cache.Ehcache ehcache =
        jHipsterProperties.getCache().getEhcache();

    jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(
        CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
            ResourcePoolsBuilder.heap(ehcache.getMaxEntries()))
            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(ehcache.getTimeToLiveSeconds(), TimeUnit.SECONDS)))
            .build());
}

/**
 * EhCache configuration
 * 
 * @return
 */
@Bean
@Primary
public JCacheManagerCustomizer cacheManagerCustomizer() {
    return cm -> {          
        cm.createCache(com.david.coinlender.domain.News.class.getName(), jcacheConfiguration);

// ...More caches
}

/**
 * Java Simple Cache configuration …
Run Code Online (Sandbox Code Playgroud)

spring caching ehcache jhipster

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