javascript - AngularJS with Rails 4.2 - how to make $routeProvider.when() work properly? -
i using rails 4.2 angularjs-rails , angular-rails-templates gems. when first go home page (index.html) , try , click '#/kiteboards/{{kiteboard.id}}/users', hashbang'd url appears in browser bar, e.g., 'http://localhost:3000/#/kiteboards/1/users', users.html.haml template (courtesy of angular-rails-templates) not being loaded.
this should simple routing problem....is angularjs routing code wrong? or else? no js error messages appear in chrome dev tools console, seems angularjs wired correctly, maybe missing "/" somewhere in routing.
angularjs code snippet
var kiteapp = angular.module('kiteapp', ['ngresource', 'ngroute', 'templates']); kiteapp.controller('kitectr', ['$scope', 'kiteboardapi', kitectr]); kiteapp.factory('kiteboardapi', ['$resource', kiteboardapi]); kiteapp.config(['$routeprovider', function($routeprovider) { $routeprovider.when('/kiteboards/:kiteboard_id/users', { templateurl: 'users.html', resolve: { usersdata: function(kiteboardapi) { return kiteboardapi.fetchusers({ kiteboard_id: $route.current.params.kiteboard_id }).$promise.then(function(data) { return data; }); } }, controller: 'kitectr' }) }]);
application.js
//= require jquery //= require jquery_ujs //= require angular //= require angular-resource //= require angular-route //= require angular-rails-templates //= require_tree ../templates //= require_tree .
in app/assets/templates/users.html.haml:
%div#section{"ng-app"=>"kiteapp", "ng-controller"=>"kitectr"} %table %thead %tr %th name %tbody %tr{"ng-repeat" => "user in usersdata track $index"} %td
home page, index.html, loaded rails
%div{"ng-app"=>"kiteapp", "ng-controller"=>"kitectr"} %table %thead %tr %th index # %th name %tbody %tr{"ng-repeat" => "kiteboard in kiteboards track $index"} %td {{$index}} %td %a{href: '#/kiteboards/{{kiteboard.id}}/users'} {{kiteboard.name}}
Comments
Post a Comment