小编Ash*_*ble的帖子

如何在angularjs ui-router中的状态之间共享$ scope数据?

如果不在父控制器中使用服务或构建观察者,那么如何让儿童状态访问主控制器$scope.

  .state("main", {
      controller:'mainController',
      url:"/main",
      templateUrl: "main_init.html"
  })  
  .state("main.1", {
      controller:'mainController',
      parent: 'main',
      url:"/1",
      templateUrl: 'form_1.html'
  })  
  .state("main.2", {
      controller:'mainController',
      parent: 'main',
      url: "/2",
      templateUrl: 'form_2.html'
  })  
Run Code Online (Sandbox Code Playgroud)

我无法在子状态下访问mainController范围 - 或者说我正在获取该范围的另一个实例 - 而不是我想要的.我觉得我错过了一些简单的事情.状态对象中有一个共享数据配置选项,但我不确定是否应将此类用于此类.

javascript angularjs angularjs-scope angular-ui-router

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

自动装配同一类的两个不同的bean

我有一个包装连接池的类,该类从spring配置获取其连接细节,如下所示:

<bean id="jedisConnector" class="com.legolas.jedis.JedisConnector" init-method="init" destroy-method="destroy">
    <property name="host" value="${jedis.host}" />
    <property name="port" value="${jedis.port}" />
</bean>
Run Code Online (Sandbox Code Playgroud)

此bean稍后在服务中使用,并使用@Autowire注释自动装配.

我的问题是,我如何复制这个bean并给它不同的连接细节,然后@Autowire在服务中.意思除了上面我还会:

<bean id="jedisConnectorPOD" class="com.legolas.jedis.JedisConnector" init-method="init" destroy-method="destroy">
    <property name="host" value="${jedis.pod.host}" />
    <property name="port" value="${jedis.pod.port}" />
</bean>
Run Code Online (Sandbox Code Playgroud)

并在服务中:

@Autowired //bean of id jedisConnector
JedisConnector beanA;

@Autowired //bean of id jedisConnectorPOD
JedisConnector beanB;
Run Code Online (Sandbox Code Playgroud)

java spring annotations

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

使用Swagger/Swashbuckle的OAUTH Web API

我试图让我的Web API项目使用Swagger'漂亮'文档等(http://swagger.io/)

我正在使用Swashbuckle for .NET,从NuGet安装,我使用的版本是4.0.1

我已经能够安装和使用Swagger了.此时一切似乎都很正常.我唯一的障碍是禁用API密钥并能够使用OAuth,就像在PetStore示例中一样(http://petstore.swagger.wordnik.com/#!/pet/addPet)

我已经尝试了我能在网上找到的所有东西.我在下面列出它们:

首先,这是我的Startup.cs

public void Configuration(IAppBuilder app)
{
    var config = new HttpConfiguration();

    WebApiConfig.Register(config);

    Swashbuckle.Bootstrapper.Init(config);
}
Run Code Online (Sandbox Code Playgroud)

现在,我的SwaggerConfig.cs:

public static void Register()
{
    Swashbuckle.Bootstrapper.Init(GlobalConfiguration.Configuration);

    SwaggerSpecConfig.Customize(c =>
    {
        c.IgnoreObsoleteActions();

        c.IncludeXmlComments(GetXmlCommentsPath());

        c.ApiInfo(new Info
        {
            Title = "Work you",
            Description = "testing some stuffs",
            Contact = "Email@email.com"
        });

        c.Authorization("oauth2", new Authorization
        {
            Type = "oauth2",
            Scopes = new List<Scope>
                {
                    new Scope { ScopeId = "products.read", Description = "View products" },
                    new Scope { ScopeId …
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api swagger

15
推荐指数
2
解决办法
2万
查看次数

使用 moment.js 确定当前时间(以小时为单位)是否在特定时间之间

我正在开发一个功能,可以用时间感知的问候语(早上好,下午,晚上,晚上)向用户打招呼。这是我制作的脚本

import moment from "moment";

function generateGreetings(){
    if (moment().isBetween(3, 12, 'HH')){
        return "Good Morning";
    } else if (moment().isBetween(12, 15, 'HH')){
        return "Good Afternoon";
    }   else if (moment().isBetween(15, 20, 'HH')){
        return "Good Evening";
    } else if (moment().isBetween(20, 3, 'HH')){
        return "Good Night";
    } else {
        return "Hello"
    }
}

$("greet")
.css({
    display: "block",
    fontSize: "4vw",
    textAlign: "center",
    })
.text(generateGreetings() +", name")
Run Code Online (Sandbox Code Playgroud)

但它根本不起作用,只返回“Hello”。我也尝试过使用

var currentTime = moment();
var currentHour = currentTime.hour();
Run Code Online (Sandbox Code Playgroud)

并用于在函数内部currentHour进行替换,但是当我这样做时,该网站就会消失。moment()希望这里的任何人都知道我应该做什么来解决这个问题。

javascript time momentjs

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

为什么 NavLink 中的 activeClassName 属性在 React Router 6.0.2 版本中不起作用?

我使用 activeClassName 属性在链接处于活动状态时向链接添加一个新类。它在 React-router-dom 5.0.3 版本中运行良好。但在版本 6.0.2 中它开始向我显示警告并且它不起作用。我无法在react-router website 给出的文档中找到有关此更改的任何描述。

 <NavLink
    className={classes.registerButton}
    activeClassName={classes.active}
    to="/auth/SignUp"
  >cart</NavLink>
Run Code Online (Sandbox Code Playgroud)

开发者控制台中显示的警告图像

reactjs react-router-dom

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

如何在react-bootstrap中居中对齐容器组件的内容?

我的容器组件如下所示:

<Container className="contact-content debug-border">
    <Row className="justify-content-center">
        <Col md={2} className="text-center text-md-right">
            Phone:
        </Col>
        <Col md={3} className="text-center text-md-left">
            XXXXXXXXX
        </Col>
    </Row>
    <Row className="justify-content-center">
        <Col md={2} className="text-center text-md-right">
            Email-ID:
        </Col>
        <Col md={3} className="text-center text-md-left">
            XXXXXXXXXXX
        </Col>
    </Row>
</Container>
Run Code Online (Sandbox Code Playgroud)

我的CSS如下:

.contact-content{
    height: 83vh;
}

.debug-border{
    border: 2px;
    border-style: dashed;
}
Run Code Online (Sandbox Code Playgroud)

它看起来是这样的: 在此输入图像描述 我想要的是电话和电子邮件数据的行和列显示在页面中间

我尝试过的:

我尝试向容器添加类:

  • 对齐内容中心
  • 对齐项目中心
  • 内容居中对齐
  • 项目中间对齐
  • 中间对齐
  • 我的汽车
  • py自动

它对网页的外观没有任何影响。

我将 padding:40vh 添加到 contact-content css 类中,它起作用了,但我想知道 bootstrap 中是否有任何类可以将容器内的行和列与页面中间对齐。

css css-position reactjs react-bootstrap bootstrap-4

7
推荐指数
0
解决办法
3万
查看次数

java异常处理中的return语句

如果执行不会导致异常,则控制转到finally块.那么JVM是否会忽略try块中的return语句?.或者如果发生异常,那么控制进入catch块也会忽略返回状态并且控制转到finally块并从最终返回

  public class Helper {
     public int showException(int a, int b){

           try{
           int c=a/b;
           return c;
           } catch(Exception e){
                return 0;
           } finally{
               return 3;
             }
     }
  }
Run Code Online (Sandbox Code Playgroud)

java exception-handling

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

Wrapped AggregateException仅报告ToString方法中的第一个异常

当我直接使用ToString()method 时,我得到完整的嵌套异常集AggregateException:

public void GreenTest()
{
    var ex = new AggregateException(new Exception("ex1"), new Exception("ex2"));

    ex.ToString()
        .Should()
        .Contain("ex1")
        .And
        .Contain("ex2");
}
Run Code Online (Sandbox Code Playgroud)

问题是当我被AggregateException另一个异常包装时,我只得到第一个异常:

public void RedTest()
{
    var ex = new Exception("wrapper", new AggregateException(new Exception("ex1"), new Exception("ex2")));

    ex.ToString()
        .Should()
        .Contain("wrapper")
        .And
        .Contain("ex1")
        .And
        .Contain("ex2");
}
Run Code Online (Sandbox Code Playgroud)

ex2在结果字符串中不存在.这是一个错误或类的一些众所周知的功能AggregateException

c# aggregateexception

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

CORS政策不想与SignalR和ASP.NET Core一起使用

我的ASP.NET核心API和Angular Client有问题。我想实现SignalR在API和Angular之间建立连接。cors策略已在我们的客户端和API上激活,因为我们已经可以使用我们的客户端从API检索数据。但是现在的问题是,当我尝试使用SignalR时,收到CORS POLICY错误:

通过CORS策略已阻止从源“ http:// localhost:4200 ” 访问“ http:// localhost:50501 / CoordinatorHub / negotiate ” 处的XMLHttpRequest :对预检请求的响应未通过访问控制检查:否'访问-Control-Allow-Origin'标头出现在请求的资源上。

但是我们的API上的Startup.cs内部已经有cors政策,就像这样:

在ConfigureServices方法中:

services.AddCors(options =>
{
    options.AddPolicy("AllowSpecificOrigin",
        builder => 
        builder.WithOrigins("http://localhost:4200/")
            .AllowCredentials()
            //.AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader()
            .SetIsOriginAllowedToAllowWildcardSubdomains());
});
Run Code Online (Sandbox Code Playgroud)

在Configure方法中:

app.UseCors("AllowSpecificOrigin");
Run Code Online (Sandbox Code Playgroud)

在我们的客户端中,我们只想尝试在API和客户端之间建立连接,就像这样:

this.hubConnection.start({withCredentials: false}).then(() => 
     this.hubConnection.invoke('send', 'Hello'));
Run Code Online (Sandbox Code Playgroud)

cors signalr asp.net-core angular angular7

6
推荐指数
5
解决办法
1234
查看次数

ASP.NET Core SignalR 使用 Azure AD 返回 401 未经授权

我有一个 SPA (Angular 7) 和一个 API (.Net Core),我使用 Azure AD 对其进行身份验证。我正在使用adal-angular4将我的角度应用程序与 AAD 集成。

一切都很好,但我也使用 SignalR 和 API 作为服务器,当我尝试从 SPA 连接时,我在协商“请求”上收到 401 Unauthorized 消息,并在响应标头中得到此消息:

响应头

该请求在 Authorization 标头中包含我的 Bearer 令牌,当我通过jwt.io运行该令牌时,我可以看到“aud”值是我的 SPA 的 Azure AD ClientId。

对 API 的所有常规请求都包含相同的令牌,我对此没有任何问题。我的所有控制器和集线器上都有[授权],但只有 SignalR 集线器会导致此问题。

我的服务器启动:

public Startup(IConfiguration configuration, IHostingEnvironment env)
{
    Configuration = configuration;
    _env = env;
}

public IConfiguration Configuration { get; }
private IHostingEnvironment _env;
public void ConfigureServices(IServiceCollection services)
{

    StartupHandler.SetupDbContext(services, Configuration.GetConnectionString("DevDb"));


    // Setup Authentication
    services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
        .AddAzureADBearer(options =>
        {
            Configuration.Bind("AzureAD", …
Run Code Online (Sandbox Code Playgroud)

c# signalr azure-active-directory asp.net-core angular

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