javascript - Angular $routeParams is empty -
i have url that's getting passed angular code via rails. however, when try pick parameter in url, shows blank. can me out?
sample url: http://localhost:3000/events/event1
plnkr: http://plnkr.co/edit/yg8wazhhgpth2pbfzql3?p=preview
angular:
eventsapp = angular.module('eventsapp', ['ngroute']) eventsapp.config [ '$routeprovider' '$locationprovider' ($routeprovider, $locationprovider) -> $locationprovider.html5mode(true) $routeprovider.when '/events/:eventname', templateurl: '../../views/events/events.html.erb' controller: 'eventsctrl' return ] eventsapp.controller('eventsctrl', [ '$scope' '$routeparams' ($scope, $routeparams) -> console.log($routeparams.eventname) # shows undefined $scope.greeting = $routeparams.eventname ])
html:
events.html.erb
<div> {{greeting}} </div>
application.html.erb (overall layout)
<div id="content" ng-app="eventsapp"> <div ng-view></div> <%= yield %> </div>
edit: suggested, i've moved ng-app
, ng-view
layout , kept div inside events.html.erb
it's because have included controller ng-controller
directive instead of ng-view
. must this:
<body ng-app="eventsapp"> <div ng-view></div> </body>
in events.html.erb
:
<div> {{greeting}} </div>
Comments
Post a Comment