I have an simple AngularJS application with a service holding a collection.
There is a navigation view with a form and its controller adding to the collection. The view in included with an ng-include attribute in the index.html file:
<div ng-include="'views/nav.html'"></div><div ng-view="">
There is also another view and its controller to display the collection content. This view is called in with a route statement in the app/scripts/app.js file:
.when('/link/list/', {
templateUrl: 'scripts/domain/link/view/list.html',
controller: 'linkListController'
})
But this other view not showing anything when I try adding up items in the form at the /#/link/list/ address, and no collection item is shown in the view.
I feel like my navigation controller is not sharing the collection with the display list view.
Here is the list collection controller:
app.controller('linkListController', function ($scope, $log, loggingService, firebaseLinkService, LinksService) {
});
Here its list.html view:
<div class="post row" ng-repeat="link in links">
<a href="{{ link.url }}">
{{ link.title }}
<span class="url">({{ link.url | hostnameFromUrl }})</span>
</a>
</div>
Here is the navigation controller:
app.controller('navController', function ($scope, $log, $location, loggingService, firebaseLinkService, LinkService, LinksService) {
$scope.addLink = function() {
$scope.link = LinkService;
$scope.links = LinksService;
var linkUrlId = firebaseLinkService.push($scope.link);
var pathArray = linkUrlId.toString().split('/');
var linkId = pathArray[pathArray.length - 1];
$scope.link.id = linkId;
$scope.links.push($scope.link);
$scope.link = {id: '', url: '', title: ''};
};
});
And its view:
<div ng-controller="navController">
<form ng-submit="addLink()">
<input type="text" ng-model="link.title">
<input type="text" ng-model="link.url">
<button type="submit" >Submit</button>
</form>
</div>
I would think my two controllers are root controllers since they are done on the app oject with a app.controller(). Is it the case ? And if so, is they scope then the root scope ?
Kind Regards,
Stephane Eybert