javascript - 我无法加载模板 Angular JS + Ionic + Gulpjs

标签 javascript angularjs ionic-framework

设置 gulp 任务后,我无法在 Ionic 中加载模板,这是我使用 firebug 时遇到的错误:

  Cannot GET /templates/login.html

这是我的项目树

app  
   controllers
   services
   templates/
      login.html
   index.html
   app.js
vendors : bower directory 
web:  this is the deployment directory 
  templates/
     login.html  the gulp task copy the file 

这是完整的gulp文件:

'use strict';

var gulp    = require('gulp');
var connect = require('gulp-connect');
var uglify  = require('gulp-uglify');
var concat  = require('gulp-concat');
var historyApiFallback = require('connect-history-api-fallback');

/**
 * Deploying the compress vendors
*/
gulp.task('vendors', function () {
  gulp.src('./vendors/**')
    .pipe(gulp.dest('./www/lib'))
    .pipe( connect.reload() );
});
/**
 * Deploying the templates in  www
*/
gulp.task('templates',function(){
  gulp.src( './app/templates/**/*.html')
      .pipe( gulp.dest( './www/js/templates') )
      .pipe( connect.reload() );
});


/**
 * Deployting the compress factories in www
*/
gulp.task( 'factories', function(){
  gulp.src('./app/core/**/*.js')
      .pipe( uglify({mangle: false}) )
      .pipe( concat('factories.js') )
      .pipe( gulp.dest('./www/js/') )
      .pipe( connect.reload() );
});
/**
 * Deployting the compress services in www
*/
gulp.task( 'services', function(){
  gulp.src('./app/services/**/*.js')
      .pipe( uglify({mangle: false}) )
      .pipe( concat('services.js') )
      .pipe( gulp.dest('./www/js/') )
      .pipe( connect.reload() );
});

/**
 * Deploying the compress controllers in www
*/
gulp.task( 'controllers', function(){
  gulp.src('./app/controllers/**/*.js')
      .pipe( uglify({mangle: false}) )
      .pipe( concat('controllers.js') )
      .pipe( gulp.dest('./www/js/') )
      .pipe( connect.reload() );
});

/**
 * Deployting the app in www
*/
gulp.task( 'app', function(){
  gulp.src('./app/app.js')
      .pipe( uglify({mangle: false}) )
      .pipe( concat('app.js') )
      .pipe( gulp.dest('./www/js') );
});

gulp.task( 'index', function(){
  gulp.src('./app/index.html')
      .pipe( gulp.dest('./www/') )
      .pipe( connect.reload() );
});

gulp.task( 'watch',function(){
    gulp.watch( ['./app/templates/**/*.html'], ['templates'] );
    gulp.watch( ['./app/controllers/**/*.js'], ['controllers']);
    gulp.watch( ['./app/core/**/*.js'],        ['factories']);
    gulp.watch( ['./app/services/**/*.js'],    ['services'] );
    gulp.watch( ['./app/app.js'],              ['app'] );
    gulp.watch( ['./app/index.html'], ['index'] );
});


 // Servidor web de desarrollo
 gulp.task('server', function() {
     connect.server({
       root: './app',
       hostname: '0.0.0.0',
       port: 8080,
       livereload: true,
       middleware: function(connect, opt) {
         return [ historyApiFallback ];
       }
     });
});

var tareas = [
  'vendors','index','templates', 'factories', 'services','controllers','app', 'watch'
];



gulp.task('default',tareas);

这是我要部署的 app.js:

var app =   angular.module('rondas', ['ionic']);


app.run(['$ionicPlatform',function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });

}]);
app.config(['$stateProvider','$urlRouterProvider','$httpProvider',function( $stateProvider,$urlRouterProvider,$httpProvider ){
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
    $stateProvider.state('login', {
      url: '/',
      templateUrl: 'templates/login.html',
      controller : 'LoginController'
    });
    $urlRouterProvider.otherwise('/');
}]);

奇怪的是,当我运行 gulp 任务时,文件被复制到预期的目录中,但是当我使用 ionic serve 运行应用程序时和 Firebug 我收到错误。

这是ionic.project文件:

{
  "name": "irondas",
  "app_id": "",
  "gulpStartupTasks": [
    "vendors","templates", "factories", "services","controllers","app", "watch"
  ]
}

您可以查看所有来源here

那我不知道我做错了什么?

最佳答案

您的 gulp 进程将模板文件放入 www/js/templates 目录,而不是您建议的 web/templates 目录:

.pipe( gulp.dest( './www/js/templates') )

也许你想放

.pipe( gulp.dest( './web/templates') )

相反?

关于javascript - 我无法加载模板 Angular JS + Ionic + Gulpjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133299/

相关文章:

ionic-framework - 如何禁用/删除 ionic 按钮 Ionic 4 中的 ionic 波纹效果?

javascript - 如何避免react中重复的事件监听器?

javascript - AngularJS 简单 Controller 不工作

angular - Ionic:侧边菜单子(monad)菜单(下拉)

node.js - Connect.sid 始终未定义并且 req.session ID 不断重置

javascript - Angular $watchCollection 回调不捕获对象中的更改

javascript - 将 angular-bootstrap-calendar 安装到 Ionic App 中时出现问题

javascript - 在登录页面重定向之前防止主页闪烁

javascript - videojs 皮肤 vim 没有覆盖原始样式。

javascript - 以编程方式关闭 Liferay 对话框