小编Tja*_*alt的帖子

Angular2 IE11无法获取未定义或空引用的属性"apply"

将angular2包升级到以下版本后,出现以下错误:

  • @ angular/common":"^ 2.3.1
  • @ angular/compiler":"^ 2.3.1
  • @ angular/core":"^ 2.3.1
  • @ angular/forms":"^ 2.3.1
  • @ angular/http":"^ 2.3.1
  • @ angular/platform-b​​rowser":"^ 2.3.1"
  • @ angular/platform-b​​rowser-dynamic":"^ 2.3.1
  • @ angular/platform-server":"^ 2.3.1
  • @ angular/router":"^ 3.3.1

错误:Unable to get property 'apply' of undefined or null reference

在此输入图像描述

我只在IE11中收到此错误,在Chrome中它运行正常.

我做了一些挖掘,导致错误的行在angular/common模块中:

function combine(options) {
  return (_a = ((Object))).assign.apply(_a, [{}].concat(options));
  var _a;
}
Run Code Online (Sandbox Code Playgroud)

打字稿文件:

@ angular/common/src/pipes/intl.ts第175行

function combine(options: Intl.DateTimeFormatOptions[]): Intl.DateTimeFormatOptions {
  return (<any>Object).assign({}, ...options);
}
Run Code Online (Sandbox Code Playgroud)

调用该combine函数的代码是 @ angular/common/src/pipes/intl.ts第48行:

'yMMMdjms': datePartGetterFactory(combine([


UPDATE

似乎实际的错误是.assignIE11中没有实现该方法

javascript typescript angular

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

错误:无法重新附加从其他路径创建的ActivatedRouteSnapshot

我正在尝试实现这个RouteReuseStrategy课程.当我导航到顶级路径时,它工作正常.

一旦路径有子路径并导航到子路径,然后导航回顶级路径我收到以下错误:

错误:未捕获(在承诺中):错误:无法重新附加从其他路径创建的ActivatedRouteSnapshot

我创建了一个用于演示错误的plunker.我发现在IE 11中,plunker不起作用,请在最新版本的Chrome中查看

重现错误的步骤:

步骤1: 在此输入图像描述

第2步 在此输入图像描述

第三步: 在此输入图像描述

第4步 在此输入图像描述

您可以在控制台中查看错误: 在此输入图像描述

我已经尝试了本文中的实现

export class CustomReuseStrategy implements RouteReuseStrategy {

    handlers: {[key: string]: DetachedRouteHandle} = {};

    shouldDetach(route: ActivatedRouteSnapshot): boolean {
        console.debug('CustomReuseStrategy:shouldDetach', route);
        return true;
    }

    store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
        console.debug('CustomReuseStrategy:store', route, handle);
        this.handlers[route.routeConfig.path] = handle;
    }

    shouldAttach(route: ActivatedRouteSnapshot): boolean {
        console.debug('CustomReuseStrategy:shouldAttach', route);
        return !!route.routeConfig && !!this.handlers[route.routeConfig.path];
    }

    retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
        console.debug('CustomReuseStrategy:retrieve', route);
        if (!route.routeConfig) return null;
        return this.handlers[route.routeConfig.path];
    }

    shouldReuseRoute(future: ActivatedRouteSnapshot, …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-routing angular

22
推荐指数
1
解决办法
4281
查看次数

AngularJS脚本标记JSON-LD

如何application/ld+json script在AngularJS中使用动态构建的JSON对象创建标记.

这就是我需要脚本标签的样子

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Place",
  "geo": {
    "@type": "GeoCoordinates",
    "latitude": "40.75",
    "longitude": "73.98"
  },
  "name": "Empire State Building"
}
</script>
Run Code Online (Sandbox Code Playgroud)

我尝试了以下代码,但我无法让它工作:

HTML

<div ng-controller="TestController">
  <script type="application/ld+json">
    {{jsonId|json}}
  </script>
  {{jsonId|json}}
</div>
Run Code Online (Sandbox Code Playgroud)

调节器

var myApp = angular.module('application', []);

myApp.controller('TestController', ['$scope', function($scope) {
  $scope.jsonId = {
    "@context": "http://schema.org",
    "@type": "Place",
    "geo": {
      "@type": "GeoCoordinates",
      "latitude": "40.75",
      "longitude": "73.98"
    },
    "name": "Empire State Building"
  };
}]);
Run Code Online (Sandbox Code Playgroud)

脚本标记内的表达式不会执行.脚本标记外部的表达式正确执行并显示JSON

请看jsfiddle

javascript json angularjs json-ld

17
推荐指数
1
解决办法
3950
查看次数

Entityframework是否在创建时自动分配导航属性

当我运行下面提到的代码时,EF保存PersonAddress正确PersonId.我没有PersonAddress实体添加到Person实体,即使我没有这样做,我的数据库中的记录也正确链接.

我的问题是:即使我没有指定它所属的实体,EF是否会自动添加相关实体?如果是这样,这不会导致不必要的实体关系?

更新

由于以下原因,似乎正确保存了实体:

  1. 创建实体时,PersonPersonId字段为0
  2. PersonAddress.PersonId 在创建时也是0.

通过Person.PersonId在创建时手动设置为任意值,然后设置PersonAddress.PersonId为相同的Person.PersonIdEF 值,可以在共享数据时正确保存数据PersonId.

因此从技术上讲EF并不会增加相关实体自动的,因为它们共享相同的它们是相关的PersonId.

请参阅以下代码作为参考:

        using (var context = new Models.TestEntities())
        {
            var person = context.People.Create();

            var postalAddress           = context.PersonAddresses.Create();
            postalAddress.AddressLine1  = "PostalAddressLine1";

            var residentialAddress          = context.PersonAddresses.Create();
            residentialAddress.AddressLine1 = "ResidentialAddressLine1";

            context.People.Add(person);
            context.PersonAddresses.Add(postalAddress);
            context.PersonAddresses.Add(residentialAddress);

            context.SaveChanges();
        }
Run Code Online (Sandbox Code Playgroud)

当我Person在代码中添加额外内容时,我收到以下错误: 在此输入图像描述
码:

        using (var context = new …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

部分属性名称匹配意外地自动映射属性

我有两个类被映射.源类有一个DateTime属性,它被映射到type long(DateTime.Ticks)的目标属性,它们分别是UpdateDtUpdateDtTicks.

当我使用Automapper映射这两个类时,我的UpdateDtTicks属性自动从属性中获取值UpdateDt,即使属性名称不相同,并且我没有显式设置此属性的映射.

Automapper是否自动设置属性,因为属性名称最后只有不同?如果不是为什么会发生这种情况,因为它是意外的行为.

请参阅以下代码:

static void Main(string[] args)
{
    Configuration.Configure();

    var person = new OrderDto 
    {
        OrderId  = 999,
        MyDate   = new DateTime(2015, 1, 1, 4, 5, 6)
    };

    var orderModel = Mapper.Map<OrderModel>(person); 

    Console.WriteLine(new DateTime(orderModel.MyDateTicks.Value));
    Console.ReadLine();           
}

public class OrderDto 
{
    public int      OrderId  { get; set; }
    public DateTime MyDate   { get; set; }
}

public class OrderModel 
{
    public int      OrderId     { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# automapper

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

如何使用带有表单数据主体而不是 json 主体的 http 'POST'?(Angular2/Typescript)

我有一些想要执行的请求,到目前为止,我使用带有 json 的 http.post ,如下所示:

this.http.post("https://somepath.com/users/login", JSON.stringify({"email": "someone@gmail.com","password":"123","user_token":"sss"}), RequestOptionsArgs);
Run Code Online (Sandbox Code Playgroud)

但这是行不通的,因为对该网站的请求需要是表单数据主体...我如何才能接受相同的调用并将其更改为表单数据?

谢谢!

json http typescript angular

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

dictionary.TryGetValue vs FirstOrDefault

根据MSDN文档,一个Tuple对象Equals方法将使用两个Tuple对象的值.

为什么以下内容不会产生相同的结果:

[Test]
public void TestTupleWithDictionary() 
{
    Dictionary<Tuple<string, string>, string> values = new Dictionary<Tuple<string, string>, string>();

    values.Add(new Tuple<string, string>("1", "1"), "Item 1");
    values.Add(new Tuple<string, string>("1", "2"), "Item 2");

    Assert.IsNotNull(values.FirstOrDefault(x => x.Key == new Tuple<string, string>("1", "2")));

    string value;
    values.TryGetValue(new Tuple<string, string>("1", "2"), out value);

    Assert.IsNotNullOrEmpty(value);
}
Run Code Online (Sandbox Code Playgroud)

为什么values.FirstOrDefault(x => x.Key == new Tuple<string, string>("1", "2"))回到null这里为values.TryGetValue(new Tuple<string, string>("1", "2"), out value);找到正确的键和返回值?

c# linq dictionary compare tuples

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