简体   繁体   English

使用ES6类和extend关键字构建的Angular Services在IE11中导致未知提供程序错误

[英]Angular Services built with ES6 classes and the extend keyword causing Unknown provider error in IE11

Currently an angular 1.5 client I am using is throwing lots of unknown provider errors on IE11. 目前,我正在使用的有角度的1.5客户端在IE11上引发许多未知的提供程序错误。 I've currently narrowed down the problem to the use of the 'extends' keyword in our service files . 我目前已将问题缩小为在服务文件中使用'extends'关键字

Something about them either isn't being properly transpiled by babel or isn't properly interpreted by the browser. 关于它们的某些事情或者没有被babel正确地编译,或者没有被浏览器正确地解释。

Service: 服务:

'use strict';

import RequestService from './request.service';

const path = 'users';

/**
 * @class
 * @extends RequestService
 */
export default class UserService extends RequestService {
  /**
   * @param  {Object} $q - angular promise library
   * @param  {Object} $http - angular http service
   * @param  {Object} appConfig - app config object
   */
  constructor($q, $http, appConfig, AuthService, BorrowerService, SellerService) {
    'ngInject';
    super($q, $http, appConfig, path);

    this.AuthService = AuthService;
    this.BorrowerService = BorrowerService;
    this.SellerService = SellerService;
  }

Injection: 注射:

export function run($auth, $rootScope, $window, $state, $stateParams, $uibModalStack, UserService) {
  'ngInject'; 

Module: 模块:

const module = angular
  .module('sba.core', [...])
  .run(routesRun);

Does anyone know exactly what's breaking here? 有人知道这里到底发生了什么吗? From what I've read Babel should support the extends keyword for any browser that supports prototype.__proto__ . 据我所读,Babel应该为所有支持prototype.__proto__浏览器都支持extend关键字。

Versions: 版本:

Node v6.8.0 节点v6.8.0
Angularjs v1.5.8 Angularjs v1.5.8
babel-core v6.18.2 babel-core v6.18.2
babel-polyfill v6.16.0 babel-polyfill v6.16.0

This issue actually turned out to be more complex than I initially thought. 实际上,这个问题比我最初想象的要复杂。 Several issues ended up playing a part in it. 最终导致了几个问题。 The 'extends' statement, using 'import' to grab the class that we were extending. 'extends'语句,使用'import'来获取我们正在扩展的类。 We were able to fix it however by making sure to initialize the services with an explicit string rather than using class.name. 但是,我们可以通过确保使用显式字符串而不是使用class.name初始化服务来解决此问题。

import UserService from './user.service';
// this cause unknown provider error
angular.service(UserService.name, UserService);

// this works
angular.service('UserService', UserService);

This really underscores how important it is to register services with String literals instead of references. 这确实突显了使用String文字而不是引用注册服务的重要性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM