javascript - Angular Js: Getting data from URL via $routeParams & $scope -
i have issue trying pass info url using $routeparams in $scope in angular js. here html partial:
<h1>this is: {{project[currentcat].id}}</h1> //works <h3>test: {{project[currentcat].examples[currentex].id}}</h3> //doesn't <h2>category: {{project[currentcat].id | capitalize}}</h2> the h1 tag works have set in javascript so:
categorycontrollers.controller('datacontroller', ['$scope', '$http','$routeparams', function($scope, $http, $routeparams) { $http.get('json/data.json').success(function(data) { $scope.project = data; $scope.currentcat = $routeparams.cat; //works $scope.currentex = $routeparams.ex; //works unable info and app config:
.when('/:cat', { templateurl: 'partials/details.html', //works controller: 'datacontroller' }) .when('/:cat/:ex', { templateurl: 'partials/example.html', //routes correctly unable info controller: 'datacontroller' })
and lastly json structure:
{ "animation":{ "id":"animation", "desc":"this description of animation", "images":{ "src":"images/animation.jpg", "alt":"animation image" }, "examples":[ { "id":"example1", "name":"animation project 1", "category":"animation", } ] }, basically want able pull info associated illustration based on it's name in url not sure how formulate part below.
<h3>test: {{project[currentcat.id].examples[currentex].id}}</h3> edit: here html previous partial containing link:
<li ng-repeat="example in project[currentcat].examples"> <a href="#/{{project[currentcat].id}}/{{example.id}}"> <img ng-src="images/{{item.id}}.jpg" alt="photo of {{example.name}}"></img> <div> <h2>{{example.name}}</h2> <h3>{{example.level}}</h3> <h3>{{example.desc}}</h3> <h3>{{item.description}}</h3> </div> </a> </li> any help appreciated!
your link seek reach #/animation/eample1 , trying convert data[animation] valid , data['animation'].examples['example1'] not because examples array needs accesed through numeric index if want utilize id need convert array hash
javascript angularjs scope
No comments:
Post a Comment