Monday, February 27, 2017

[SOLVED]Laravel mix and AngulaJs

I'm trying to use Laravel Mix, which runs webpack, to compile an angular app into one file. I get the error:
Uncaught ReferenceError: app is not defined

my 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');

my 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');
....

My 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
}]);

I get the Uncaught ReferenceError: app is not defined when I call app.controller(), for example app/Controller/aboutController.js:
app.controller("aboutController", ['$scope', '$rootScope', '$http', function ($scope, $rootScope, $http) {....}

Am i missing something? If i load all the file one by one using html it works fine.


from Latest question asked on Laravel tag.


via paolo.basso99

Advertisement