小编Nam*_*pal的帖子

通用无状态组件的类型是什么?或者在typescript中扩展泛型函数接口以进一步通用?

问题:界面Stateless Functional Component给出为

interface SFC<P = {}> {
    (props: P & { children?: ReactNode }, context?: any): ReactElement<any> | null;
    propTypes?: ValidationMap<P>;
}
Run Code Online (Sandbox Code Playgroud)

我的组件的prop类型也是通用的:

interface Prop<V>{
    num: V;
}
Run Code Online (Sandbox Code Playgroud)

如何正确定义我的组件?如:

const myCom: <T>SFC<Prop<T>> = <T>(props: Prop<T>)=> <div>test</div>
Run Code Online (Sandbox Code Playgroud)

在给出了一个错误character 27的是Cannot find name 'T'

这是:Modifiedcript Playground的修改示例

MyFindings:

1:Typescript 2.9.1支持有状态通用组件:http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements

class myCom<T> extends React.Component<Prop<T>, any> {
   render() {
      return <div>test</div>;
   }
}
Run Code Online (Sandbox Code Playgroud)

2:扩展SFC以创建一个新接口,如下面的答案中所述,将使组件的prop类型为any: Typescript使用我不想要的泛型参数/返回类型的React无状态函数.我想为我的道具提供合适的类型

javascript generics typescript reactjs

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

在spec.js中找不到变量angular使用Webpack + Karma + Jasmine进行AngularJS单元测试

我在测试角度应用程序时遇到以下错误.

Can't find variable: angular in spec/abc.spec.js
Run Code Online (Sandbox Code Playgroud)

我的应用程序运行良好的webpack.因果报应成功

expect(true).toBe(true);
Run Code Online (Sandbox Code Playgroud)

以下是我的骨架:

在此输入图像描述

abc.ts

var angular = require('angular');
var angular_mocks = require('angular-mocks');
var specs = require('../spec/abc.spec.js');

var myApp = angular.module('myApp',[]);

myApp.controller('MyController', function($scope) {
  $scope.spices = [{"name":"pasilla", "spiciness":"mild"},
                   {"name":"jalapeno", "spiciness":"hot hot hot!"},
                   {"name":"habanero", "spiciness":"LAVA HOT!!"}];
  $scope.spice = "habanero";
});
Run Code Online (Sandbox Code Playgroud)

abc.spec.js

describe('myController function', function () {

describe('myController', function () {
    var $scope;

    beforeEach(angular.mock.module('myApp'));

    beforeEach(inject(function ($rootScope, $controller) {
        $scope = $rootScope.$new();
        $controller('MyController', {$scope: $scope});
    }));

    it('should create "spices" model with 3 spices', function () {
        expect($scope.spices.length).toBe(3); …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine angularjs karma-runner webpack

7
推荐指数
1
解决办法
1423
查看次数

应该为自定义Interceptor类和包使用什么命名约定,以避免Struts2中的struts.xml

我有兴趣知道是否有任何约定在struts2中命名自定义拦截器,以便自动检测拦截器,就像动作类一样.

我正在使用" struts2-convention-plugin-2.3.24.1.jar ".

包结构如下

ProtienTracker
    >Java Resources
        >src
            >com.nagarro.actions
                >HelloAction.java
            >com.nagarro.interceptors
                >custInterceptor.java
    >WebContent
        >META_INF
        >WEB_INF
            >content
                >hello.jsp
            >lib
        >web.xml
Run Code Online (Sandbox Code Playgroud)

代码在没有" struts.xml "且没有" custInterceptor "的情况下运行完美.struts2-convention-plugin自动检测到该操作.

只要我附上拦截器

@org.apache.struts2.convention.annotation.Action(value="hello",
    interceptorRefs=@InterceptorRef("custInterceptor"))
Run Code Online (Sandbox Code Playgroud)

我收到错误,如下所示.

文件如下

为hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Hello</title>
</head>
<body>
    <h1><s:property value="greeting"/></h1>
    <p>hi</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

HelloAction.java

package com.nagarro.actions;
import com.opensymphony.xwork2.Action;

import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
public class HelloAction …
Run Code Online (Sandbox Code Playgroud)

java jsp struts2

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

如何在 Angular5 中通过“httpclient”删除请求传递正文

如何在删除请求中通过httpClient传递body?

请检查我的代码。有什么想法可以在删除请求中通过正文传递数据吗?没有正确的来源如何在 Angular 5 中调用此请求。

let body = removeFile;
    return this.httpClient.delete(`${apiRoot}RemoveQueryData`, {
      headers: new HttpHeaders().set('Content-Type', 'application/json').set('Authorization', `Bearer ${accessToken}`),
      observe: removeFile
    })
Run Code Online (Sandbox Code Playgroud)

我正在观察那个身体。它抛出以下错误。

错误:

Error: Unreachable: unhandled observe type [object Object]}
    at HttpClient.request (http.js:1520)
    at HttpClient.delete (http.js:1546)
Run Code Online (Sandbox Code Playgroud)

httpclient http-delete angular angular4-httpclient angular5

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