-1
AngularJS 1.6 componentコントローラの内部でクラスをインポートするには、どのような構文を使用する必要がありますか?AngularJS 1.6コンポーネントコントローラでクラスをインポートするには?
たとえば、次のコンポーネントがあります。
アプリ/電話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
を受け取る
babel-standaloneを使用します。
import Player from './player.js';
このファイルを質問に追加できますか? –
質問がどのように角度またはコントローラに関連しているのか分かりません。 [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)の構文に特に問題はありますか? – estus