启用html5Mode时使用angular和express进行路由

时间:2015-09-16 03:09:59

标签: angularjs http express url-routing

我有一个角度路由'/iniciar-sesion'它用控制器检索视图,我想知道的是关于快速路由,我可以在express中创建相同的路由来处理get和post方法吗?如果是这样的话?

到目前为止我所做的是:

  • 角度路由(启用html5Mode)
  • 创建快递路线
  • 声明了get和post函数

现在发生的事情是,当我没有快速路线时,角度渲染静态页面,但是当我有快速路线时,它会永远保留,直到它显示No Data Received

我如何告诉express发送数据,以及如何接收它(使用Restangular)?

EXPRESS

index.js

module.exports = (function () {

    var express = require('express'),
        router = express.Router(),
        signin = require('./signin.controller');

    router.route( '/iniciar-sesion' )
        .get( signin.get )
        .post( signin.post );

    return router;

})();

controller.js

module.exports = (function() {

    models  = require('../../components/db/models');

    function  get( req, res ) {

        models.users.findAll().then(function(users) {
            //Maybe i have to assign to res the users
            console.log(users);
        });
        console.log('Log In Get');

    }

    function  post( req, res ) {

        console.log('Log In Post');

    }

    return {
        get: get,
        post: post
    }

})();

routes.js

(function () {

    'use strict';

    angular.module('app.users.auth')

        // Collect the ui-route states
        .constant('states', getRouteStates())

        // Configure the ui-route states and state resolvers
        .config(['$stateProvider', '$urlRouterProvider', 'states', stateConfigurator]);

    function stateConfigurator($stateProvider, $urlRouterProvider, states) {

        states.forEach(function (state) {

            $stateProvider.state(state.name, state.config);

        });

        $urlRouterProvider.otherwise("/");

    }

    // Define the ui-route states
    function getRouteStates() {
        return [
            {
                name: 'signin',
                config: {
                    url: '/iniciar-sesion',
                    templateUrl: 'modules/users/auth/signin/signin.view.html',
                    title: 'Iniciar Sesion',
                    controller: 'SignInController',
                    controllerAs: 'vm'
                }
            }
        ];
    }

})();

controller.js

(function () {

    'use strict';

    angular
        .module('app.users.auth')
        .controller('SignInController',[function () {
            //Some restangular code
        }]);

})();

0 个答案:

没有答案