小编jen*_*gar的帖子

等待所有承诺解决

所以我有一种情况,我有多个未知长度的承诺链.我希望在处理完所有CHAINS后运行一些操作.这甚至可能吗?这是一个例子:

app.controller('MainCtrl', function($scope, $q, $timeout) {
    var one = $q.defer();
    var two = $q.defer();
    var three = $q.defer();

    var all = $q.all([one.promise, two.promise, three.promise]);
    all.then(allSuccess);

    function success(data) {
        console.log(data);
        return data + "Chained";
    }

    function allSuccess(){
        console.log("ALL PROMISES RESOLVED")
    }

    one.promise.then(success).then(success);
    two.promise.then(success);
    three.promise.then(success).then(success).then(success);

    $timeout(function () {
        one.resolve("one done");
    }, Math.random() * 1000);

    $timeout(function () {
        two.resolve("two done");
    }, Math.random() * 1000);

    $timeout(function () {
        three.resolve("three done");
    }, Math.random() * 1000);
});
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我设置了一个$q.all()承诺一,二和三,这将在一些随机时间得到解决.然后我将承诺添加到第一和第三的末尾.我想要all解决所有链都已解决的问题.这是我运行此代码时的输出:

one done 
one doneChained …
Run Code Online (Sandbox Code Playgroud)

promise angularjs angular-promise

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

Android Gradle找不到符号类Gson

所以我将gson-2.2.4.jar添加到libs目录(我正在使用android studio).我的项目找不到gson的东西,所以我在"项目结构"中将它作为库依赖项添加到我的模块中.当我尝试运行该项目时,构建失败并出现以下错误:

Error:(12, 23) Gradle: package com.google.gson does not exist
Error:(37, 3) Gradle: cannot find symbol class Gson
Error:(37, 19) Gradle: cannot find symbol class Gson
Run Code Online (Sandbox Code Playgroud)

为什么我不能让这个工作?我在别处读到gradle应该自动处理所有内容,如果它放在lib目录中.

android gradle android-gradle-plugin

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

测试指令需要控制器

所以我确实看到了另一个问题:如何在指令UT中模拟必需的指令控制器,这基本上是我的问题,但似乎这个线程的答案是"改变你的设计".我想确保没有办法做到这一点.我有一个指令声明了一个由children指令使用的控制器.我现在正在尝试为children指令编写jasmine测试但是我不能让它们在测试中编译,因为它们依赖于控制器.这是它的样子:

addressModule.directive('address', ['$http', function($http){
        return {
            replace: false,
            restrict: 'A',
            scope: {
                config: '='
            },
            template:   '<div id="addressContainer">' +
                            '<div ng-if="!showAddressSelectionPage" basic-address config="config"/>' +
                            '<div ng-if="showAddressSelectionPage" address-selector addresses="standardizedAddresses"/>' +
                        '</div>',
            controller: function($scope)
            {
                this.showAddressInput = function(){
                    $scope.showAddressSelectionPage = false;
                };

                this.showAddressSelection = function(){
                    $scope.getStandardizedAddresses();
                };

                this.finish = function(){
                    $scope.finishAddress();
                };
            },
            link: function(scope, element, attrs) {
              ...
            }
       }
}])
Run Code Online (Sandbox Code Playgroud)

儿童指令:

addressModule.directive('basicAddress360', ['translationService', function(translationService){
        return {
            replace: true,
            restrict: 'A',
            scope: {
                config: '='
            },
            template:
                '...',
            require: …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs

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

使用$ http拦截器重试请求

我确信有一种简单的方法可以做我想做的事情,我只是无法绕过它.如果失败,我怎样才能获得角度的http拦截器来重试请求?我想我必须在请求中建立某种承诺吗?然后在响应中我将不得不检查响应是否是错误,如果是,那么做出承诺吗?怎么做的?我一直试图改变这里的例子:http://docs.angularjs.org/api/ng.$http

我试图使用拦截器的原因是因为我需要在请求URL中添加令牌和其他一些东西,以及处理xdr的一些事情.

javascript angularjs

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

在java配置中添加http安全过滤器

我试图在春季添加网络安全性,但我不希望过滤器适用于某些事情.怎么在java中完成?

也许还有更好的方法,因为我创建了一个自定义过滤器,但这是我认为实例化它的唯一方法,因为它的依赖性.

总的来说,我想做的是:

/resources/**不应该通过过滤器, /login(POST)不应该通过过滤器,其他一切都应该通过过滤器

通过我在春天发现的各种例子我能够想出一个开始,但它显然不起作用:

@Configuration
@EnableWebSecurity
@Import(MyAppConfig.class)
public class MySecurityConfig extends WebSecurityConfigurerAdapter
{
    @Override
    public void configure(WebSecurity webSecurity) throws Exception
    {
        webSecurity.ignoring().antMatchers("/resources/**");
    }

    @Override
    public void configure(HttpSecurity httpSecurity) throws Exception
    {
        httpSecurity
                .authorizeRequests()
                .antMatchers("/resources/**").permitAll()
                .antMatchers("/login").permitAll();

        httpSecurity.httpBasic();
        httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

    @Bean
    @Autowired
    public TokenFilterSecurityInterceptor<TokenInfo> tokenInfoTokenFilterSecurityInterceptor(MyTokenUserInfoCache userInfoCache, ServerStatusService serverStatusService, HttpSecurity httpSecurity) throws Exception
    {
        TokenService<TokenInfo> tokenService = new TokenServiceImpl(userInfoCache);
        TokenFilterSecurityInterceptor<TokenInfo> tokenFilter = new TokenFilterSecurityInterceptor<TokenInfo>(tokenService, serverStatusService, "RUN_ROLE");
        httpSecurity.addFilter(tokenFilter);
        return tokenFilter;
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

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

用spring混合xml和java配置

我正在构建一个新的应用程序,通过java配置而不是xml配置spring.此应用程序依赖于使用xml样式配置的模块.当我尝试启动我的应用程序时,出现以下错误:

No qualifying bean of type [com.myModule.myServiceImp] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)

该bean应该在模块的applicationContext.xml中声明.处理这个问题的正确方法是什么?我试着简单地添加它,如果我在应用程序的web.xml中将应用程序上下文串起来的话:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:com/myModule/appbase-context.xml
            com.myApp.AppConfig
        </param-value>
    </context-param>
Run Code Online (Sandbox Code Playgroud)

但我仍然有同样的错误.这样做的正确方法是什么?

java xml spring

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

在promise链中使用await

我刚刚升级到节点8,并希望开始使用async/await.我遇到了一个错误,我花了一些时间来解决这个错误,实际上我只是想知道是否有更优雅的方式.我不希望在这个时间点重构整个函数,因为它会导致所有的二级重构.

async doSomething(stuff) {
...

  return functionThatReturnsPromise()
    .then((a) => ...)
    .then((b) => ...)
    .then((c) => {
      const user = await someService.createUser(stuff, c);
      user.finishSetup();
    });
};
Run Code Online (Sandbox Code Playgroud)

有没有办法能够await在承诺链中使用而不必重构以上所有内容async

javascript node.js async-await

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

将JSON对象绑定到angularjs中的单选按钮

所以我试图将单选按钮绑定到对象.我花了一个小时试图解决这个问题,最后承认失败.这是我得到的:

<table>
        <tr ng-repeat="theCustomer in customers">
            <td>
                <input type="radio" ng-model="currentCustomer" value="theCustomer" id="{{theCustomer.id}}" ng-change="currentCustomer = theCustomer">
                <label for="{{theCustomer.id}}">{{theCustomer.name}}</label>
            </td>
        </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

有角度的东西:

bankApp.controller("BankController", function ($scope, CustomerRepository)
{
    $scope.customers = [];
    $scope.currentCustomer = {};

    $scope.createCustomer = function () {
        CustomerRepository.save($scope.customer, function (customer) {
            $scope.customers.push(customer);
            $scope.customer = {};
        });
    };
});
Run Code Online (Sandbox Code Playgroud)

目前,当我尝试单击单选按钮时没有任何反应,它甚至没有标记得到检查.我确信必须有一个非常简单的解决方案.最终目标是让currentCustomer客户反映在无线电选择中.

angularjs

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

注释类型预期

我刚刚创建了这个单元测试,然后在@Test"预期注释类型" 下得到了一个红色的波浪形.这是什么意思?

package com.sample.bank.account;

import junit.framework.Test;
import static org.junit.Assert.*;

public class LoanTest {

    @Test
    public void testAppliyPaymentSubtractsCorrectAmount()
    {
        Loan loan = new Loan("test subtract", 1000);
        loan.applyPayment(100);
        assertEquals(900, loan.getBalance());
    }
}
Run Code Online (Sandbox Code Playgroud)

junit intellij-idea

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

当元素被启用/禁用时触发功能

这似乎是一个相对简单的事情,但我找不到任何关于如何做的事情.我有一个模态,在等待异步数据时打开一个禁用的输入.我想知道什么时候输入启用,我可以集中输入.这就是我想要完成的.将其视为全局模态打开处理程序:

$('.modal').on('shown.bs.modal', function (event) {
    var textInput = $(event.target).find('input[type=text]:visible').first();
    if (textInput.is(':disabled'))
    {
        textInput.on('<<<<<enabled>>>>>', function(){
            textInput.off('<<<<<enabled>>>>>');
            textInput.focus();
        });
    }
    else
    {
        textInput.focus();
    }
});
Run Code Online (Sandbox Code Playgroud)

输入启用/禁用时是否没有触发事件?

<input type="text" class="form-control txtUserSearch" data-bind="value: userFilter, event: { keyup: FilterUsers }, enable: AvailableUsers().length > 0">
Run Code Online (Sandbox Code Playgroud)

如果在异步请求中返回了用户,则会启用该功能.

html javascript jquery twitter-bootstrap knockout.js

11
推荐指数
1
解决办法
3953
查看次数