ng-view not working with partials in AngularJS/Express

后端 未结 3 835
忘掉有多难
忘掉有多难 2021-01-19 00:14

Everything was working until I tried to display a partial file in ng-view.

/public/app/app.js

angular.module(\'app\', [\'ngResource\         


        
相关标签:
3条回答
  • 2021-01-19 00:56
      app.get('*', function(req, res,next) {
         if(req.xhr != true)
           {
             res.render('index');
           } else
           {
           next();
        }
            });
    

    modify like this

    0 讨论(0)
  • 2021-01-19 01:03

    Not sure how much this will help but I notice all the bower packages are in the 'bower_components' directory. That is the default for bower unless you specify another directory. So, if you want the bower components installed say, '/public/vendor', do the following:

    1) create a file called ' .bowerrc ' and save it in your root directory ie. with gitignore, bower.json, etc.

    2) in the file put:

    {
      "directory": "public/vendor"
    }
    

    That will load the bower components where you want them. The file ' .bowerrc ' is a config file for bower and you can find the guidance at: http://bower.io/

    HTH

    0 讨论(0)
  • 2021-01-19 01:08

    Thers is something off in your app.js file. Replace it with this and you should be good to go:

    var app = angular.module('app', ['ngResource', 'ngRoute']);
    
    angular.module('app').config(function($routeProvider, $locationProvider){  
        $locationProvider.html5Mode(true);
        $routeProvider
            .when('/', { templateUrl: '/partials/main', controller: 'mainCtrl'});
    });
    
    
    angular.module('app').controller('mainCtrl', function($scope){  
        $scope.myVar = "Hello Angular";
    });
    
    0 讨论(0)
提交回复
热议问题