如果我想在AngularJS 1.6 component控制器中导入一个类,我必须使用什么语法?
例如,我有以下组件。
应用/电话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.'
}
];
}
});
我在一个单独的文件player.js
中定义了一个类。
player.js
export default class Player {
constructor () {
// define properties
}
loadVideo () {
// do stuff
}
playVideo () {
// do stuff
}
}
我想在PhoneListController()
内使用此类:
let player = new Player();
player.loadVideo();
player.playVideo();
...
如果我将它放在控制器文件中,该类就可以工作。
如果我尝试按以下方式导入,则会收到unexpected token import
:
import Player from './player.js';