Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs应用程序崩溃,出现“故障”;错误:递归太多“;定义路线时_Javascript_Jquery_Angularjs_Node.js - Fatal编程技术网

Javascript Angularjs应用程序崩溃,出现“故障”;错误:递归太多“;定义路线时

Javascript Angularjs应用程序崩溃,出现“故障”;错误:递归太多“;定义路线时,javascript,jquery,angularjs,node.js,Javascript,Jquery,Angularjs,Node.js,我将按照本教程介绍如何与laravel一起使用angularjs:。但是,如果我在config.routes.js中定义了一个指向控制器、任何控制器的路由,我的应用程序就会崩溃。在控制台中出现错误“error:too-more recursion”以及无用的堆栈跟踪 我的所有文件都与教程中的完全相同,我只更改了路线和控制器的名称,但这不会有什么区别 我在谷歌上搜索了一下,似乎这个错误可能是由于使用了错误版本的jquery造成的。我使用angularjs 1.3.0,我不知道我的应用程序使用的是哪

我将按照本教程介绍如何与laravel一起使用angularjs:。但是,如果我在config.routes.js中定义了一个指向控制器、任何控制器的路由,我的应用程序就会崩溃。在控制台中出现错误“error:too-more recursion”以及无用的堆栈跟踪

我的所有文件都与教程中的完全相同,我只更改了路线和控制器的名称,但这不会有什么区别

我在谷歌上搜索了一下,似乎这个错误可能是由于使用了错误版本的jquery造成的。我使用angularjs 1.3.0,我不知道我的应用程序使用的是哪个jquery版本,但我使用了
npm install angular
,所以如果安装了错误的版本,那会很奇怪,对吗

我完全不明白为什么会发生这种情况,也非常沮丧,所以任何帮助都将不胜感激

谢谢

编辑:添加代码:

app/js/config.routes.js

angular.module('app').config(function($routeProvider, $locationProvider)
{
    $locationProvider.html5Mode(true).hashPrefix('!');

    $routeProvider.when('/transactions', 
    {
        templateUrl: 'features/transactions/transactions.tpl.html',
        controller: 'Transactions'
    });
});
app/js/transactions/transactions.js:

angular.module('app').controller('Transactions', function($scope, $http)
{
    $http.get('/api/transactions').then(function(result) 
    {
        $scope.shows = result.data;
    });
});
transactions.tpl.html为空

app.js:

angular.module('app', ['ngRoute']);
编辑2:添加gulp.js 我唯一改变的是,我添加了“webserver”任务

var gulp    = require('gulp');
var fs      = require('fs');
var plugins = require('gulp-load-plugins')();
var es      = require('event-stream');
var del     = require('del');

var publicFolderPath = '../public';

var paths = {
  appJavascript:     ['app/js/app.js', 'app/js/**/*.js'],
  appTemplates:      'app/js/**/*.tpl.html',
  appMainSass:       'app/scss/main.scss',
  appStyles:         'app/scss/**/*.scss',
  appImages:         'app/images/**/*',
  indexHtml:         'app/index.html',
  vendorJavascript:  ['vendor/js/angular.js', 'vendor/js/**/*.js'],
  vendorCss:         ['vendor/css/**/*.css'],
  finalAppJsPath:    '/js/app.js',
  finalAppCssPath:   '/css/app.css',
  specFolder:        ['spec/**/*_spec.js'],
  publicFolder:      publicFolderPath,
  publicJavascript:  publicFolderPath + '/js',
  publicAppJs:       publicFolderPath + '/js/app.js',
  publicCss:         publicFolderPath + '/css',
  publicImages:      publicFolderPath + '/images',
  publicIndex:       publicFolderPath + '/angular.html',
  publicJsManifest:  publicFolderPath + '/js/rev-manifest.json',
  publicCssManifest: publicFolderPath + '/css/rev-manifest.json'
};

gulp.task('scripts-dev', function() {
  return gulp.src(paths.vendorJavascript.concat(paths.appJavascript, paths.appTemplates))
    .pipe(plugins.if(/html$/, buildTemplates()))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.sourcemaps.write('.'))
    .pipe(gulp.dest(paths.publicJavascript));
});
gulp.task('scripts-prod', function() {
  return gulp.src(paths.vendorJavascript.concat(paths.appJavascript, paths.appTemplates))
    .pipe(plugins.if(/html$/, buildTemplates()))
    .pipe(plugins.concat('app.js'))
    .pipe(plugins.ngAnnotate())
    .pipe(plugins.uglify())
    .pipe(plugins.rev())
    .pipe(gulp.dest(paths.publicJavascript))
    .pipe(plugins.rev.manifest({path: 'rev-manifest.json'}))
    .pipe(gulp.dest(paths.publicJavascript));
});

gulp.task('styles-dev', function() {
  return gulp.src(paths.vendorCss.concat(paths.appMainSass))
    .pipe(plugins.if(/scss$/, plugins.sass()))
    .pipe(plugins.concat('app.css'))
    .pipe(gulp.dest(paths.publicCss));
});

gulp.task('styles-prod', function() {
  return gulp.src(paths.vendorCss.concat(paths.appMainSass))
    .pipe(plugins.if(/scss$/, plugins.sass()))
    .pipe(plugins.concat('app.css'))
    .pipe(plugins.minifyCss())
    .pipe(plugins.rev())
    .pipe(gulp.dest(paths.publicCss))
    .pipe(plugins.rev.manifest({path: 'rev-manifest.json'}))
    .pipe(gulp.dest(paths.publicCss));
});

gulp.task('images', function() {
  return gulp.src(paths.appImages)
    .pipe(gulp.dest(paths.publicImages));
});

gulp.task('indexHtml-dev', ['scripts-dev', 'styles-dev'], function() {
  var manifest = {
    js: paths.finalAppJsPath,
    css: paths.finalAppCssPath
  };

  return gulp.src(paths.indexHtml)
    .pipe(plugins.template({css: manifest['css'], js: manifest['js']}))
    .pipe(plugins.rename(paths.publicIndex))
    .pipe(gulp.dest(paths.publicFolder));
});

gulp.task('indexHtml-prod', ['scripts-prod', 'styles-prod'], function() {
  var jsManifest  = JSON.parse(fs.readFileSync(paths.publicJsManifest, 'utf8'));
  var cssManifest = JSON.parse(fs.readFileSync(paths.publicCssManifest, 'utf8'));

  var manifest = {
    js: '/js/' + jsManifest['app.js'],
    css: '/css/' + cssManifest['app.css']
  };

  return gulp.src(paths.indexHtml)
    .pipe(plugins.template({css: manifest['css'], js: manifest['js']}))
    .pipe(plugins.rename(paths.publicIndex))
    .pipe(gulp.dest(paths.publicFolder));
});

gulp.task('lint', function() {
  return gulp.src(paths.appJavascript.concat(paths.specFolder))
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('jshint-stylish'));
});

gulp.task('testem', function() {
  return gulp.src(['']) // We don't need files, that is managed on testem.json
    .pipe(plugins.testem({
      configFile: 'testem.json'
    }));
});

gulp.task('clean', function(cb) {
  del([paths.publicJavascript, paths.publicImages, paths.publicCss, paths.publicIndex], {force: true}, cb);
});

gulp.task('watch', ['indexHtml-dev', 'images'], function() {
  gulp.watch(paths.appJavascript, ['lint', 'scripts-dev']);
  gulp.watch(paths.appTemplates, ['scripts-dev']);
  gulp.watch(paths.vendorJavascript, ['scripts-dev']);
  gulp.watch(paths.appImages, ['images-dev']);
  gulp.watch(paths.specFolder, ['lint']);
  gulp.watch(paths.indexHtml, ['indexHtml-dev']);
  gulp.watch(paths.appStyles, ['styles-dev']);
  gulp.watch(paths.vendorCss, ['styles-dev']);
});

gulp.task('webserver', ['indexHtml-dev', 'images-dev'], function() {
  plugins.connect.server({
    root: paths.tmpFolder,
    port: 5000,
    livereload: true,
    middleware: function(connect, o) {
      return [ (function() {
        var url = require('url');
        var proxy = require('proxy-middleware');
        var options = url.parse('http://localhost:8000/api');
        options.route = '/api';
        return proxy(options);
      })(), historyApiFallback ];
    }
  });
});

gulp.task('default', ['watch']);
gulp.task('production', ['scripts-prod', 'styles-prod', 'images', 'indexHtml-prod']);

function buildTemplates() {
  return es.pipeline(
    plugins.minifyHtml({
      empty: true,
      spare: true,
      quotes: true
    }),
    plugins.angularTemplatecache({
      module: 'app'
    })
  );
}

angular不依赖于jquery。如果需要帮助,请显示相关代码添加(我认为)相关的代码段。我猜您缺少此-$routeProvider。否则('/transactions');不,那也不行。我添加了我的gulp.js文件,可能问题出在那里?你的应用程序何时崩溃?启动时?点击页面?在构建期间?