简体   繁体   中英

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. I've currently narrowed down the problem to the use of the 'extends' keyword in our service files .

Something about them either isn't being properly transpiled by babel or isn't properly interpreted by the browser.

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__ .

Versions:

Node v6.8.0
Angularjs v1.5.8
babel-core v6.18.2
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. We were able to fix it however by making sure to initialize the services with an explicit string rather than using 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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