小编Joe*_*oel的帖子

使用AngularJS中的Promises成功/错误/ finally/catch

$http在AngularJs中使用,我不确定如何使用返回的promise并处理错误.

我有这个代码:

$http
    .get(url)
    .success(function(data) {
        // Handle data
    })
    .error(function(data, status) {
        // Handle HTTP error
    })
    .finally(function() {
        // Execute logic independent of success/error
    })
    .catch(function(error) {
        // Catch and handle exceptions from success/error/finally functions
    });
Run Code Online (Sandbox Code Playgroud)

这是一个很好的方法吗,还是有更简单的方法?

promise angularjs angularjs-http

111
推荐指数
5
解决办法
19万
查看次数

在Xcode故事板中使用可伸缩的图像

我正在使用故事板来布置我的视图控制器,我想为我的按钮使用可伸缩的图像(这样我就不需要生成几个不同大小的图像).

这可以直接在故事板中直接进行,而无需编写任何代码吗?我真的很喜欢将故事板用于所有图形内容的可能性,并保持代码清洁UI的东西,但似乎我无法在这里摆脱它.

如果不可能,你会建议什么呢?

iphone xcode cocoa-touch ios uistoryboard

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

没有ASP.NET MVC的捆绑和缩小

是否可以在没有MVC项目的情况下使用Microsoft.AspNet.Web.Optimization中的捆绑和缩小?

我正在创建一个与REST API通信的AngularJS站点.对于REST API,我使用的是ASP.NET Web API.我还创建了一个"ASP.NET空Web应用程序".此项目中只有HTML,js和CSS文件(以及web.config).我想将我的js和CSS文件捆绑和缩小,但我不想创建一个MVC项目来获得它.可能吗?

c# asp.net asp.net-mvc visual-studio-2012 bundling-and-minification

23
推荐指数
2
解决办法
8927
查看次数

将大型AngularJS模块配置重构为单独的文件

问题:很大 config()

我的AngularJS应用程序的配置变得越来越大.您如何将以下内容重构为单独的文件?

// app.js
angular.module('myApp')
    .config(function($urlRouterProvider, $stateProvider, $httpProvider) {
        // Configure routing (uiRouter)
        $urlRouterProvider.when('/site', '/site/welcome');
        $stateProvider.state('main', ...
        ...

        // Configure http interceptors
        $httpProvider.interceptors.push(function () {              
            ...
        });
    });
Run Code Online (Sandbox Code Playgroud)

选项1多config()小号

我知道我可以有多个config()s并将它们放在单独的文件中,如下所示:

// app.js
angular.module('myApp');

// routerConfiguration.js
angular.module('myApp')
    .config(function($urlRouterProvider, $stateProvider) {
        // Configure routing (uiRouter)
        $urlRouterProvider.when('/site', '/site/welcome');
        $stateProvider.state('main', ...
        ...

// httpInterceptorConfig.js
angular.module('myApp')
    .config(function($httpProvider) {
        // Configure http interceptors
        $httpProvider.interceptors.push(function () {              
            ...
        });
    });
Run Code Online (Sandbox Code Playgroud)

我不喜欢这个,就是在原来的app.js中,没有办法概述启动时运行的内容.


选项2.注入某些东西

我更喜欢这样做,因为直接在app.js中查看配置会更容易.但是我知道这是不可能的,因为我们无法注入服务config().

我可以用提供商来解决这个问题吗?有没有更好的办法?

// app.js
angular.module('myApp')
    .config(function(routerConfig, …
Run Code Online (Sandbox Code Playgroud)

angularjs

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

IIS Express在调试会话结束时不会停止

当我在Visual Studio 2017中停止调试网站时,IIS Express不再停止.

我不确定这种行为何时开始,但我有以下设置:

  • Visual Studio 15.5.2(已修复)
  • IIS Express 10.0 x64(重新安装)
  • ASP.Net Core 2项目目标 net461
  • 我在工具 - >选项 - >调试 - >常规中禁用了"启用编辑并继续"

不知道什么时候开始发生,也许当我更新到最新的VS版本时.

我还能尝试什么?

iis-express asp.net-core visual-studio-2017 asp.net-core-2.0

17
推荐指数
5
解决办法
4977
查看次数

使用SqlFileStream从WCF服务返回流

我有一个WCF服务,用户可以从中请求大型数据文件(存储在启用了FileStream的SQL数据库中).这些文件应该流式传输,并且在发送之前不会加载到内存中.

所以我有以下方法应该返回一个由WCF服务调用的流,以便它可以将Stream返回给客户端.

public static Stream GetData(string tableName, string columnName, string primaryKeyName, Guid primaryKey)
    {
        string sqlQuery =
            String.Format(
                "SELECT {0}.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM {1} WHERE {2} = @primaryKey", columnName, tableName, primaryKeyName);

        SqlFileStream stream;

        using (TransactionScope transactionScope = new TransactionScope())
        {
            byte[] serverTransactionContext;
            string serverPath;
            using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ToString()))
            {
                sqlConnection.Open();

                using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                {
                    sqlCommand.Parameters.Add("@primaryKey", SqlDbType.UniqueIdentifier).Value = primaryKey;

                    using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                    {
                        sqlDataReader.Read();
                        serverPath = sqlDataReader.GetSqlString(0).Value;
                        serverTransactionContext = sqlDataReader.GetSqlBinary(1).Value;
                        sqlDataReader.Close();
                    }
                }
            } …
Run Code Online (Sandbox Code Playgroud)

c# sql wcf filestream

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

在Angular 2应用程序中为所有路径使用基准防护

canActivate在Angular2中配置路由时有没有办法设置"基础" ?因此,所有路由都由相同的基本检查覆盖,然后每个路由可以进行更细化的检查.

我有这样的AppModule路由:

@NgModule({
    imports: [
        RouterModule.forRoot([
            {
                path: '',
                component: HomeComponent,
                canActivate: [AuthenticationGuardService],
                data: { roles: [Roles.User] }
            }
        ])
    ],
    exports: [
        RouterModule
    ]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

对于功能模块FeatureModule:

@NgModule({
    imports: [
        RouterModule.forChild([
            {
                path: "feature",
                component: FeatureComponent,

                // I'd like to avoid having to do this:
                canActivate: [AuthenticationGuardService],
                data: { roles: [Roles.User] }
            }
        ])
    ],
    exports: [
        RouterModule
    ]
})
export class FeatureRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

AuthenticationGuardService通过使用中提供的角色检查用户是否可以访问路由data …

angular2-routing angular2-guards angular

14
推荐指数
2
解决办法
5559
查看次数

使用反应形式将复选框绑定到值而不是true/false

我正在尝试使用反应/模型驱动形式的一个简单示例.我想将一个复选框数组绑定到值列表,而不是布尔值列表.

这个plunker显示了这个问题:http ://plnkr.co/edit/a9OdMAq2YIwQFo7gixbj?p=preview 绑定到表单的值是布尔值,我想答案是这样的["value1", "value2", etc]

我有类似的东西,但我不知道如何得到我想要的结果?

模板:

<form [formGroup]="checkboxGroup">
    <input *ngFor="let control of checkboxGroup.controls['myValues'].controls" 
    type="checkbox" id="checkbox-1" value="value-1" [formControl]="control" />
</form>
Run Code Online (Sandbox Code Playgroud)

和组件:

let checkboxArray = new FormArray([
  new FormControl({checked: true, value: "value1"}),
  new FormControl({checked: false, value: "value2"}))]);

this.checkboxGroup = _fb.group({
  myValues: checkboxArray
});
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular

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

如何使用 Dbeaver 社区版连接到 Cassandra?

有人使用 DBeaver 社区版成功连接到 Cassandra 集群吗?我尝试关注这篇文章,但没有取得任何成功。我必须启用身份验证,但收到一条错误消息:

Authentication error on host /x.x.x.x:9042: Host /x.x.x.x:9042 requires authentication, but no authenticator found in Cluster configuration

cassandra dbeaver

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

关于AverageTimer32 PerformanceCounter的困惑

我正在尝试设置一个PerformanceCounter来衡量某种方法的平均执行时间.我试过阅读AverageTimer32,我看了很多例子,但我似乎无法做到正确.

我设置了类别

CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

// Add the counter.
CounterCreationData averageTimer32 = new CounterCreationData();
averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
averageTimer32.CounterName = counterName;
CCDC.Add(averageTimer32);

// Add the base counter.
CounterCreationData averageTimer32Base = new CounterCreationData();
averageTimer32Base.CounterType = PerformanceCounterType.AverageBase;
averageTimer32Base.CounterName = baseCounterName;
CCDC.Add(averageTimer32Base);

// Create the category.
PerformanceCounterCategory.Create(categoryName, "Demonstrates usage of the AverageTimer32 performance counter type", PerformanceCounterCategoryType.SingleInstance, CCDC);
Run Code Online (Sandbox Code Playgroud)

然后我创建了计数器

PC = new PerformanceCounter(categoryName, counterName, false);

BPC = new PerformanceCounter(categoryName, baseCounterName, false);

PC.RawValue = 0;
BPC.RawValue = 0;
Run Code Online (Sandbox Code Playgroud)

最后,我每次调用方法时记录经过的时间

private …
Run Code Online (Sandbox Code Playgroud)

.net c# performancecounter

10
推荐指数
1
解决办法
1171
查看次数