如果要在AngularJS 1.6组件控制器内导入类,我必须使用什么语法?
例如,我有以下组件。
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.'
}
];
}
});
,我在单独的文件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();
...
如果我将其放在控制器文件中,则可以使用。
- 我使用babel-standalone
如果我尝试以以下方式导入unexpected token import
:
import Player from './player.js';
根据您遇到的错误。这意味着您在JavaScript Polyfill中遇到问题,请尝试此