角度路由和模板问题

时间:2014-05-05 17:37:58

标签: angularjs ruby-on-rails-4 angularjs-routing

我正在学习如何使用angularjs路由和模板,我遇到了一个问题。我在Gemfile中添加了gem,在application.js中添加了// = require angular-rails-templates,并在我的main angular.module中添加了依赖

angular.module('authentication', ['authenticationModule','ngRoute','templates'])
.config(['$routeProvider',function($provider){
$provider
.when('/sign_in', { templateUrl: '/assets/signin.html', controller: 'redirectCtrl'})
.when('/sign_up', { templateUrl: 'templates/signup.html.erb', controller: 'redirectCtrl1'})
.controller('redirectCtrl', function($location) {
$location.path('/sign_in')
})
.controller('redirectCtrl1', function($location) {
$location.path('/sign_up')
})

我的signin.html位于/assets/templates/signin.html 当我尝试加载页面时,我没有得到渲染的页面,而是我得到了这个

window.AngularRailsTemplates || (window.AngularRailsTemplates = angular.module(“templates”,[])); window.AngularRailsTemplates.run([“$ templateCache”,function($ templateCache){$ templateCache.put(“signin.html”,“\ u003cdiv ng-controller = \”authenticationCtrl \“\ u003e \ n \ t \ u003cdiv \ u003e \ n \ t \ u003ch1 \ u003e登录\ u003c / h1 \ u003e \ n \ t \ u003c / div \ u003e \ n \ t \ u003cdiv \ u003e \ n \ t \ t \ u003cdiv \ u003e \ n \ t \ t \ u003cdiv \ u003eEmail:\ u003cinput ng-model = \“email \”type = \“email \”/ \ u003e \ u003c / div \ u003e \ n \ t \ t \ t \ u003cdiv \ u003ePassword:\ u003cinput type = \“password \ “ng-model = \”password \“/ \ u003e \ u003c / div \ u003e \ n \ n \ t \ t \ u003cbutton ng-click = \”login()\“\ u003eLogin \ u003c / button \ u003e \ n \ t \ t \ u003c / div \ u003e \ n \ t \ u003c / div \ u003e \ t \ t \ t \ t \ n \ u003c / div \ u003e \ n“);}]);

解决我的问题? 提前致谢

更新1: 好的,所以我改变了以下内容,

angular.module('authentication', ['authenticationModule','ngRoute','templates'])
    .config(['$routeProvider',function($provider){
        $provider
            .when('/sign_in', { templateUrl: 'assets/signin.html', controller: 'redirectCtrl'})

            .when('/sign_up', { templateUrl: 'assets/signup.html', controller: 'redirectCtrl1'})
    }])
    .controller('redirectCtrl', function($location) {
        // $location.path('/sign_in')
    })
    .controller('redirectCtrl1', function($location) {
        // $location.path('/sign_up')
    })

这就是我现在得到的,模板加载但有一些额外的东西,我不需要 http://postimg.org/image/iuhy9dflj/

1 个答案:

答案 0 :(得分:0)

删除/之前的资源,并指向模板文件夹

angular.module('authentication', ['authenticationModule','ngRoute','templates'])
.config(['$routeProvider',function($provider){
$provider
.when('/sign_in', { templateUrl: 'assets/templates/signin.html', controller: 'redirectCtrl'})
.when('/sign_up', { templateUrl: 'templates/signup.html.erb', controller: 'redirectCtrl1'})
.controller('redirectCtrl', function($location) {
$location.path('/sign_in')
})
.controller('redirectCtrl1', function($location) {
$location.path('/sign_up')
})