i have angular page ng-repeat
through projectlist (json).
ng-repeat="project in projects"
it's structured this:
[{"number":789456,"title":"coolest project ever","manager":"darth vader","image":7,"startdate":"25.1.2013","enddate":"8.7.2015","location":"deathstar","favorited":"not"}]
so, i've made each ng-repeat
have following:
<a ng-href="#/projects/{{project.number}}"></a>
i've set route following way:
.when('/projects', { templateurl: '/views/projects.html', controller: 'projectcontroller', controlleras: 'pr', title: 'prosjekter' }) .when('/projects/:projectnumber', { templateurl: '/views/projectdetails.html', controller: 'projectcontroller', controlleras: 'pr', title: 'prosjekt' })
my controller looks this:
var app = angular.module('app'); app.controller('projectcontroller', function($scope, projectlist, $mddialog, $q, $timeout, $routeparams){ $scope.projectnumber = $routeparams.projectnumber; $scope.projects = projectlist.query(); $scope.project = $scope.projects.filter(function(project) { return project.number === $routeparams.projectnumber; })[0];
i projectlist factory called "projectlist".
my problem is, view loads correctly, have no way of accessing variables of project once i'm in 'child-view' of projects.
i tried using {{project.number}}
, doesn't work. how define in controller?
in projectcontroller,
need use $routeparams
in order refer projectnumber
defined in url.
{{project.number}}
won't available until you've defined $scope.project
. when need refer project number obtained url, use $routeparams.projectnumber
.
for example, you'd have:
app.controller('projectcontroller', ['$scope', '$routeparams', function ($scope, $routeparams) { var projects = [{...}, ...]; $scope.project = projects.filter(function(project) { return project.number === $routeparams.projectnumber; })[0]; }]);
Comments
Post a Comment