简体   繁体   中英

unable to serve json file with express.static

i have a few questions:

i am building an app with angular and node (Express).

1) in my node server i am serving all static files in my static_dir

app.use(express.static(STATIC_DIR));

insdie this dir i have a json file static_Dir/courts/courts.json

my controll is as follows:

squashApp.controller('CourtsController',
    function CourtsController($scope) {
    //$http.get('courts/courts.json').success(function(data) {
        $scope.courts = 'courts/courts.json';
  });

and my html file is:

<table class="table">
    <tr>
      <th>Hour</th>
      <th>Player 1</th>
      <th>Player 2</th>
    </tr>
    <tr>
      <td>itai</td>
      <td>asf</td>
      <td>sdf</td>
    </tr>
    <tr ng-repeat="court in courts">
      <td>{{court.hour}}</td>
      <td>{{court.player1}}</td>
      <td>{{court.player2}}</td>
    </tr>

for some reason the information on this json file isn't showing in my table. what is the reason?

another issue regarding unit tests and jasmin:

my test:

describe('controllers', function(){

  it('should create courts model', (function() {
    var scope = {},
    ctrl = new squashApp.controller.CourtsController(scope);
    expect(scope.courts.length).toBe(6)
  }));

});

but i am getting an erro that CourtsController is not defined. what should be the correct syntax in order to make the test work.

thanks.

var path = require('path');
...
app.use(express.static(path.join(__dirname, 'public')));

and

/courts/courts.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM