2
我正在嘗試使用運行webpack的Laravel Mix將角度應用程序編譯爲一個文件。我得到的錯誤:Laravel mix和AngulaJs
Uncaught ReferenceError: app is not defined
我webpack.mix.js
:
const { mix } = require('laravel-mix');
mix.js('resources/assets/js/dependencies.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
我bundle.js
:
//load angular
require('angular');
//Load Angular's plugins
require('angular-ui-router');
//Init Angular app
require('./app/app');
//Load angular controllers
require('./app/Controller/aboutController');
....
//Load angular directive
require('./app/Directive/directive');
//Load angular services
require('./app/Services/AccountService');
....
我app/app.js
:
var app = angular.module('app', ['ui.router']);
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'app/View/homeView.html',
controller: 'homeController'
})
...
}]);
app.run(['$state', '$rootScope', function ($state, $rootScope) {
//APP RUN
}]);
我得到Uncaught ReferenceError: app is not defined
當我打電話app.controller()
,例如app/Controller/aboutController.js
:
app.controller("aboutController", ['$scope', '$rootScope', '$http', function ($scope, $rootScope, $http) {....}
我這麼想嗎?如果我使用html
逐個加載所有文件,它工作正常。
謝謝,它的工作原理。 – paolobasso