小编Ger*_*hes的帖子

TypeScript - 将HTML附加到Angular 2中的容器元素

我想做的是简单地在元素上附加一些html.我检查了一些链接,我发现了不同的混淆/不工作/非推荐的/ etc解决方案.

使用javascript我会做这样的事情

var d1 = document.getElementsByClassName('one');
d1.insertAdjacentHTML('beforeend', '<div class="two">two</div>');
Run Code Online (Sandbox Code Playgroud)

如何使用typescript/angular2,RC5获得相同的结果?

编辑

具有类的元素.one由外部js生成,我无法修改它

javascript typescript angular

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

在先前的异步操作完成之前,在该上下文上开始第二操作

信息:

"System.NotSupportedException was unhandled
Message: An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Additional information: A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe."
Run Code Online (Sandbox Code Playgroud)

码:

public async Task<IEnumerable<UserLangDTO>> ImportLang(int userId)
{
    var userLangs = new List<UserLangDTO>();
    using (FirstContext ctx = new FirstContext())
    {
        if (await (ctx.UserLang.AnyAsync(u => u.UserId …
Run Code Online (Sandbox Code Playgroud)

.net c# parallel-processing asynchronous

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

如何在Angular 2中使用Scrollspy&Affix

我注意到你不能在角度2组件引导功能中使用 data-spy="affix"

有谁知道如何在角2中使用词缀和scrollspy?(例子)

twitter-bootstrap angular

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

在WinRT中使用FlipView和DataTemplateSelector动态显示项目

我正在使用Flipview和DataTemplateSelector在运行时确定要应用于我的控件中显示项目的DataTemplate.

我有两个DataTemplate,一个是静态的,第二个可以由未确定数量的项使用.

目前

我的第一个视图显示: - "这是一个测试 - 内容"

Followed by 18 other views看起来像这样: - " http://www.google.com/ 0" - " http://www.google.com/ 1" - " http://www.google.com/ 2" - 等等直到17日

我想要

要将" http://www.google.com/ " 项目分组为3 on a view.

例如,第二个视图将显示:

第三个视图将显示:

等等..

贝娄是我的代码:

FlipViewDemo.xaml

<Page.Resources>
    <DataTemplate x:Key="FirstDataTemplate">
        <Grid>
            <TextBlock Text="{Binding Content}" Margin="10,0,18,18"></TextBlock>
        </Grid>
    </DataTemplate>
    <DataTemplate x:Key="SecondDataTemplate">
        <TextBox Text="{Binding Url}"></TextBox>
    </DataTemplate>
    <local:MyDataTemplateSelector x:Key="MyDataTemplateSelector"
                FirstTextTemplate="{StaticResource FirstDataTemplate}"
                SecondTextTemplate="{StaticResource SecondDataTemplate}">
    </local:MyDataTemplateSelector> …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml windows-runtime

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

在.NET Core Web API中为MongoDB使用OData

现在,.NET Core支持OData,7.2.0已发布.但它可以与MongoDB一起使用吗?我已经搜索过,但是找不到任何说法的东西.

编辑:

我找到了一个nuget包https://www.nuget.org/packages/microsoft.aspnetcore.odata,ConfigureServices我在这里添加了这个:

这似乎对我有用:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddOData();
    services.AddSingleton<IODataModelManger, ODataModelManager>(DefineEdmModel);
    ...
}

private ODataModelManager DefineEdmModel(IServiceProvider services)
{
    var modelManager = new ODataModelManager();

    var builder = new ODataConventionModelBuilder();
    builder.EntitySet<TestDTO>(nameof(TestDTO));
    builder.EntityType<TestDTO>().HasKey(ai => ai.Id); // the call to HasKey is mandatory
    modelManager.AddModel(nameof(Something), builder.GetEdmModel());

    return modelManager;
}
Run Code Online (Sandbox Code Playgroud)

调节器

[HttpGet("all")]
public async Task<IQueryable<TestDTO>> Get()
{
    // plug your entities source (database or whatever)
    var test = await TestService.GetTest();

    var modelManager = (IODataModelManger)HttpContext.RequestServices.GetService(typeof(IODataModelManger));
    var model = modelManager.GetModel(nameof(Something));
    var …
Run Code Online (Sandbox Code Playgroud)

c# mongodb odata asp.net-web-api asp.net-core

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

EXCEPTION:根段不能有矩阵参数

HTML:

[routerLink]="['', {'scrollTo': '#contact'}]"
Run Code Online (Sandbox Code Playgroud)

TS:

this.route.params.forEach((params: Params) => {
    if (params['scrollTo']) {
        // some code here
    }
});
Run Code Online (Sandbox Code Playgroud)

错误:EXCEPTION:根段不能有矩阵参数

我的routerLink中不能有'scrollTo'参数?

它明显出现在angular 2文档中:https://angular.io/docs/ts/latest/guide/router.html#!#appendix-link-parameters-array

编辑:

似乎没有抱怨:<a [routerLink]="['/crisis-center', { scrollTo: '#contact' }]">Crisis Center</a>.但我需要用我的"根路线".

angular

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

如何使用LoggerFactory和Microsoft.Extensions.Logging进行.NET Core Console使用C#进行日志记录

我创建了一个使用服务层的控制台应用程序.

Program.cs中

public static void Main(string[] args)
{
    // Create service collection
    var serviceCollection = new ServiceCollection();
    ConfigureServices(serviceCollection);

    // Create service provider
    var serviceProvider = serviceCollection.BuildServiceProvider();

    // Entry to run app
    serviceProvider.GetService<App>().Run().RunSynchronously();
}

private static void ConfigureServices(IServiceCollection serviceCollection)
{
    // Configuration
    var configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", false)
        .Build();

    serviceCollection.AddOptions();
    serviceCollection.Configure<Settings>(options =>
    {
        //...
    });

    // Services
    serviceCollection.AddTransient<IOneService, OneService>();
    serviceCollection.AddTransient<ISecondService, SecondService>();

    // Repositories
    serviceCollection.AddTransient<MyContext, MyContext>();
    serviceCollection.AddTransient<IOneRepository, OneRepository>();

    // App
    serviceCollection.AddTransient<App>();

    // Logger

    // Automapper
    serviceCollection.AddSingleton(new AutoMapperProfileConfiguration());
    serviceCollection.AddScoped<IMapper>(sp =>
        new …
Run Code Online (Sandbox Code Playgroud)

c# logging dependency-injection nlog asp.net-core

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

无法将类型'System.Collections.IList'隐式转换为'System.Collections.Generic.List

这是我遇到的错误

错误1无法将类型隐式转换System.Collections.Generic.IList<Model.DTO.RoleDTO>System.Collections.Generic.List<Model.DTO.RoleDTO>.存在显式转换(您是否错过了演员?)

我的代码:

IList<RoleDTO> rl = new List<RoleDTO>();

        rl.Add(new RoleDTO{ roleId = new Guid("D3DCBCDA-AD61-4764-B5A1-057D654F1C26"), 
role = "admin" });


UserDTO user = new UserDTO 
             {
                username = "administrator",
                email = "administrator@email.com",
                role = rl
             };
Run Code Online (Sandbox Code Playgroud)

而型号:

namespace Model.DTO
{
    public class UserDTO
    {
        public string username { get; set; }
        public string email { get; set; }
        public IList<RoleDTO> role { get; set; }
    }

    public class RoleDTO
    {
        public Guid roleId { get; set; }
        public …
Run Code Online (Sandbox Code Playgroud)

.net c# generics

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

什么是与HttpRequestMessage等效的ASP.NET Core?

我找到了一篇博客文章,该文章显示了如何以字符串形式接收POSTed JSON。

我想知道在控制器的REST Post方法中执行与以下代码相同的操作的新的本机方法是什么:

public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
    var jsonString = await request.Content.ReadAsStringAsync();

    // Do something with the string 

    return new HttpResponseMessage(HttpStatusCode.Created);
}
Run Code Online (Sandbox Code Playgroud)

下面的另一个选项对我不起作用,我想是因为我没有Content-Type: application/json在请求标头中使用(无法更改它),并且得到415。

public HttpResponseMessage Post([FromBody]JToken jsonbody)
{
    // Process the jsonbody 

    return new HttpResponseMessage(HttpStatusCode.Created);
}
Run Code Online (Sandbox Code Playgroud)

c# rest json asp.net-core asp.net-core-webapi

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

div和childs上的Angular 2 mouseover事件

我有一个跨越孩子的div.

在我的div上我有一个mouseover事件,当我悬停在span我的事件触发器上时.

简单代码:

<div (mouseover)="showOverlay($event, FooBar)" (mouseleave)="showOverlay($event, FooBar)">
    <span>{{ someDataHere }}</span>
</div>


 public showOverlay($event, op, element): void {
    op.toggle($event, element);
    $event.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)

我想要的是在孩子身上继续显示我的叠加层,我该如何做到这一点?

javascript typescript angular

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