-1

What syntax do I have to use if I want to import a class inside a AngularJS 1.6 component controller?

For example, I have the following component.

app/phone-list.component.js

// Register `phoneList` component, along with its associated controller and template
angular.
  module('phonecatApp').
  component('phoneList', {
    template:
        '<ul>' +
          '<li ng-repeat="phone in $ctrl.phones">' +
            '<span>{{phone.name}}</span>' +
            '<p>{{phone.snippet}}</p>' +
          '</li>' +
        '</ul>',
    controller: function PhoneListController() {
      this.phones = [
        {
          name: 'Nexus S',
          snippet: 'Fast just got faster with Nexus S.'
        }, {
          name: 'Motorola XOOM™ with Wi-Fi',
          snippet: 'The Next, Next Generation tablet.'
        }, {
          name: 'MOTOROLA XOOM™',
          snippet: 'The Next, Next Generation tablet.'
        }
      ];
    }
  }); 

And I have a class defined in a separate file, player.js.

player.js

export default class Player {
  constructor () {
    // define properties
  }
  loadVideo () {
    // do stuff
  }
  playVideo () {
    // do stuff
  }
}

I want to use this class inside PhoneListController() like this:

let player = new Player();
player.loadVideo();
player.playVideo();
...

The class works if I put it in the controller file.

I receive unexpected token import if I try to import it in the following way:

import Player from './player.js';
Mistalis
  • 17,793
  • 13
  • 73
  • 97
srgbnd
  • 5,404
  • 9
  • 44
  • 80
  • 1
    Can you add that file to your question? – lenilsondc Dec 26 '16 at 12:06
  • I don't see how the question is related to Angular or a controller. Do you have any particular problems with [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) syntax? – Estus Flask Dec 26 '16 at 16:12

1 Answers1

1

according to the error that you have. It means that you have problem in JavaScript Polyfill Try this

ßastian
  • 1,814
  • 3
  • 13
  • 22