When working with Angular and angular UI-Router, my goal is to display content without relying on $scope.
In my mainController
, using directives like ng-repeat
is no problem. However, I am struggling to access information from my postsController
.
Despite successfully retrieving the correct data in my controller (as shown by console.log), I am unsure of how to access it further.
index.html
<script type="text/ng-template" id="/posts.html" >
{{ }} // What should be inserted here?
</script>
app.js
app.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
...
.state('posts', {
url: '/posts/{id}',
templateUrl: '/posts.html',
controller: 'postsController'
});
$urlRouterProvider.otherwise('home');
}
]);
app.js
app.controller('postsController', [
'$stateParams',
'posts',
function($stateParams, posts) {
var vm = this;
vm.post = posts.posts[$stateParams.id];
console.log(vm.post);
}
]);