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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -