Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to use send data from the server (node.js) to the client (front-end:angularjs) this way:

//app.js
angular.module('app').config(function($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider
        .when('/courses', { templateUrl: '/partials/courses/course-list',
            controller: 'eCourseListCtrl'
        })
        .when('/courses/:id', { templateUrl: '/partials/courses/course-details',
            controller: 'eCourseDetailCtrl'
        })
});

//eCachedCourses.js
'use strict';

angular.module('app').factory('eCachedCourses', function(eCourse) {
    var courseList;

    return {
        query: function() {
            if(!courseList) {
                courseList = eCourse.query();
            }
            return courseList;
        }
    }
});

//eCourse.js
'use strict';

angular.module('app').factory('eCourse', function($resource){
        var CourseResource = $resource('/course/:id' {id:'@id'}, {
                update: {method: 'PUT', isArray:false}
        });
        return CourseResource;
})

//eCourseListCtrl.js
 'use strict';

angular.module('app').controller('eCourseListCtrl', function($scope, eCachedCourses){
        $scope.courses = eCachedCourses.query();

        $scope.sortOptions = [{value: "title", text: "Sort by Title"},
                          {value: "date", text: "Sort by Date"}];

    $scope.sortOrder = $scope.sortOptions[0].value;
});

//routes.js
'use strict';

module.exports = function(app){
    // Profs
    app.get('/courses', function(req, res) {
      app.models.course.find().exec(function(err, courses) {
        if(err) return res.json({ err: err }, 500);
        res.send(courses);
      });
    });
}

//course-list
.container.top-padding-med
    .pull-right
        form.form-inline
            .form-group
                input.form-control(ng-model="searchText", placeholder="Filter")
            .form-group.margin-left-med
                select.form-control(ng-model="sortOrder",ng-options="item.value as item.text for item in sortOptions")
    table.table.table-hover.table-striped.table-condensed
        thead
            tr
                th Title
                th Date
                th Duration
        tbody
            tr(ng-repeat="course in courses | filter:searchText | orderBy:sortOrder")
                td
                    a(href="/courses/{{course.id}}") {{course.title}}
                td {{course.dateHour}}
                td {{course.duration}}

isn't that way to render a html page with an implicit json to be displayed ?Because when I render this, the json is displayed ! what's wrong please?

Thanks in advance!

share
    
where is the HTML? this is just the JavaScript. –  Claies 11 mins ago
    
Because the problem is here, the HTML isn't that hard to make. I'll post it if it helps you –  John Aims 7 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.