小编use*_*512的帖子

Angular 2.0绑定到样式的值

我正在尝试绑定我的类中的颜色属性(通过属性绑定获取)来设置background-color我的div.

import {Component, Template} from 'angular2/angular2';

@Component({
  selector: 'circle',
  bind:{
    "color":"color"
  }
})
@Template({
  url: System.baseURL + "/components/circle/template.html",
})
export class Circle {
    constructor(){

    }

    changeBackground():string{
        return "background-color:" + this.color + ";";
    }
}
Run Code Online (Sandbox Code Playgroud)

我的模板:

<style>
    .circle{
        width:50px;
        height: 50px;
        background-color: lightgreen;
        border-radius: 25px;
    }
</style>
<div class="circle" [style]="changeBackground()">
    <content></content>
</div>
Run Code Online (Sandbox Code Playgroud)

该组件的用法:

<circle color="teal"></circle>
Run Code Online (Sandbox Code Playgroud)

我的绑定不起作用,但也没有任何例外.如果我将{{changeBackground()}}某个地方放在模板中,那确实会返回正确的字符串.那么为什么样式绑定不起作用?

还想到它,我如何观察Circle类中color属性的变化?什么是替代品

$scope.$watch("color", function(a,b,){});
Run Code Online (Sandbox Code Playgroud)

角度2.0?

angular

76
推荐指数
5
解决办法
9万
查看次数

Angular 2,主要组件内部的组件

我在angular.io上玩过angular 2演示.现在我想创建一个新组件并在我的应用程序中使用它.

我目前的应用:

import {Component, Template, bootstrap} from 'angular2/angular2';
import {UsersComponent} from './components/users/component.js';

// Annotation section
@Component({
  selector: 'my-app'
})
@Template({
  url:"app.html"
})
// Component controller
class MyAppComponent {
  newName:string;
  names:Array<string>;
  constructor() {
    this.name = 'Florian';
  }

  showAlert(){
    alert("It works");
  }

  addName(){
    names.push(newName);
    newName = "";
  }
}

bootstrap(MyAppComponent);
Run Code Online (Sandbox Code Playgroud)

我的组件:

import {Component, Template, bootstrap} from 'angular2/angular2';
// Annotation section
@Component({
  selector: 'users'
})
@Template({
  url:"./template.html"
})
// Component controller
class UsersComponent {
  newName:string;
  names:Array<string>;
  constructor() {

  }

  addName(){
    names.push(newName);
    newName …
Run Code Online (Sandbox Code Playgroud)

angular

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

Web Api Controller在其他项目中,路由属性不起作用

我有两个项目的解决方案.一个Web Api bootstap项目,另一个是类库.

类库包含一个带属性路由的ApiController.我将web api项目中的引用添加到类库中,并希望它能够正常工作.

Web api中的路由配置为:

config.MapHttpAttributeRoutes();
Run Code Online (Sandbox Code Playgroud)

控制器很简单,看起来像:

public class AlertApiController:ApiController
{
    [Route("alert")]
    [HttpGet]
    public HttpResponseMessage GetAlert()
    {
        return Request.CreateResponse<string>(HttpStatusCode.OK,  "alert");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我转到网址"/ alert"时我得到了404.

我在这里错过了什么?为什么我不能使用这个控制器?组装肯定是加载所以我不认为http://www.strathweb.com/2012/06/using-controllers-from-an-external-assembly-in-asp-net-web-api/是答案这里.

有任何想法吗?

c# asp.net-web-api attributerouting asp.net-web-api-routing asp.net-web-api2

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

AngularJS TypeScript指令链接函数

我正在尝试使用TypeScript创建一个AngularJS指令.我的指令需要'ngModel',我也使用在我的指令中注入的自定义服务.我的主要问题是我的服务无法在我的链接功能中使用.

这是我想要实现的一个例子:

module app.directives {

    export var directiveName: string = "theDirective";

    angular.module("myApp").directive(directiveName, 
           (myFactory: app.services.MyFactory) =>
           {
                return new MyDirective(myFactory);
           });

    export interface IMyDirectiveScope extends ng.IScope {
        ngModel: ng.INgModelController;
    }

    export class MyDirective implements ng.IDirective {

        restrict = "A";
        require = "ngModel";
        scope = {
            ngModel:'='
        }

        constructor(private myFactory: app.services.MyFactory) {

        }


        link(scope: IMyDirectiveScope , elem: JQuery, attributes: ng.IAttributes, ngModel: ng.INgModelController) {
            //this is window here

            elem.bind('blur', (evt: JQueryEventObject) => {  
                 //keyword this is also window here, so yeah bummer indeed …
Run Code Online (Sandbox Code Playgroud)

angularjs typescript

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

Suave提供静态文件

我想用suave来提供我的'public'文件夹中的所有文件

在我的公开场合,我有:

/index.html
/styles/main.css
/scripts/app.js
/images/*.(png|jpg)
Run Code Online (Sandbox Code Playgroud)

我是否使用homeFolder?或者这是如何工作的?是否需要将公用文件夹复制到bin文件夹中的可执行文件旁边?我们非常感谢代码片段.谢谢.

编辑:

解决方案如下所示:

open Suave
open Suave.Filters
open Suave.Operators
open Suave.Successful
open System.IO

let app = 
    choose [
        GET >=> choose
            [path "/" >=> OK "test" ; Files.browseHome]
        POST >=> choose
            [path "/foo" >=> OK "thanks"]
    ]

let myHomeFolder = Path.Combine(Directory.GetCurrentDirectory(), "public") 

let cfg = { 
    defaultConfig with
        homeFolder = Some(myHomeFolder)
    }

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    startWebServer cfg app
    System.Console.ReadLine() |> ignore
    0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)

f# suave

9
推荐指数
1
解决办法
1350
查看次数

信号器将IHubContext转换为实际的Hub

我想知道是否可以将结果转换 var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); 为我实际的ChatHub类.因为GlobalHost.ConnectionManager.GetHubContext<ChatHub>() as ChatHub失败了

在我的ChatHub类中,我有一个方法UpdateTime():

public void SendTimeUpdate(DateTime time, string auth)
{
    Clients.All.UpdateTime(time, auth);
}
Run Code Online (Sandbox Code Playgroud)

我想从我的其他班级称呼它.由于我无法转换为ChatHub并调用SendUpdate,我必须去:

GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients.All.UpdateTime(time, auth);
Run Code Online (Sandbox Code Playgroud)

但是,如果我走这条路,方法SendTimeUpdate不会添加到代理脚本/ signalr/hubs中

有这个问题的解决方案吗?我想获取类型化的Hub实例,而不是直接在IHubContext的Clients属性上调用stuff.

c# self-hosting signalr signalr-hub

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

Owin只提供某些文件夹中的文件

所以我正在玩Owin和Katana,我想在我的公共文件夹中提供静态文件.

我有一个带有样式表和脚本文件夹的Content文件夹.

我的创业公司:

    public void Configuration(IAppBuilder app)
    {
 #if DEBUG
        //when things go south
        app.UseErrorPage();
  #endif

        // Remap '/' to '.\public\'.
        // Turns on static files and public files.
        app.UseFileServer(new FileServerOptions()
        {
            RequestPath = PathString.Empty,
            FileSystem = new PhysicalFileSystem(@".\public"),
        });

    }
Run Code Online (Sandbox Code Playgroud)

因此,如果我浏览到localhost:8861 /我去我公共文件夹中的index.html文件.没关系.但我也可以浏览我想要阻止的localhost:8861/Content/style.css.应该可以在公用文件夹中访问用户需要的所有内容.其余的都应该被阻止.

我怎样才能做到这一点?

c# static-files owin katana owin-middleware

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

ASP Identity GenerateUserTokenAsync(string purpose, TKey userId) 用途选项

所以 UserManager 有一个名为 GenerateUserTokenAsync(string purpose, TKey userId) 的函数。

这在 ASP Identity 中有什么作用?我可以使用它来生成 OAuth Bearer 令牌吗?另外目的参数是什么?这可以是什么值?

asp.net asp.net-web-api asp.net-identity

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

打字稿tsc --version仍为0.9.5

所以这是一个小问题,但是我已经安装了VS 2013 Update 2,我的Typescript编译器现在仍然说0.9.5而不是我希望的1.0.x.

有什么想法我需要安装才能解决这个问题?

updates typescript

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

使用 Windows 凭据的 F# 数据 http 请求

我正在尝试从启用了 Windows 身份验证的 IIS 托管的页面中获取一些 html。

到目前为止,我有:

open FSharp.Data

[<EntryPoint>]
let main argv = 
    let html = Http.RequestString ("http://mywebsite.com/Detail.aspx", query=[("zip","9000");("date","11/01/2017")], headers=[???])

    printf "%s" html
    System.Console.ReadLine() |> ignore
    0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)

我需要在标题列表中添加什么?

f# f#-data

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

无法在Internet Explorer 11上运行量角器

我正试图在IE11上运行我的茉莉E2E测试,但没有运气或任何东西.我在Windows 8.1上.我的配置:

exports.config = {
    directConnect: true,

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome'
    },

    // run in multiple browsers
    multiCapabilities:[
     //    {
     //        'browserName': 'chrome'
     //    },
        // {
     //        'browserName': 'firefox'
     //    },       
        {
           'browserName': 'internet explorer',
        }
    ],

    // Spec patterns are relative to the current working directly when
    // protractor is called.
    specs: ['./**/*js'],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    },

    onPrepare: function …
Run Code Online (Sandbox Code Playgroud)

testing node.js angularjs internet-explorer-11 protractor

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