I am new to angular and was looking for an example of a master detail. I found one: http://embed.plnkr.co/DBSbiV/App.js, but this is using angular's ngRoute. As I heard ui.route is the state of the art kind of way to handle routing due to it is more flexible.
I want to have both master and detail on one template, so I tried to solve it with multiple named views like in https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views. But I now have to problem, that I don't know how to create a link in the master list to the detail view with .. I tried with ... but don't know what to put right here, because I have only one state with multiple views.
Can you tell me whether I'm on the wrong way or what I put into this ref to link to my detail?
Thanks in advance
Markus
You don't actually need named views for this. Just nested views. Lets imagine you have a list of blog posts. You have one state called blogs. And another state called blogs.edit, which takes a parameter of the postId.
Your blogs.html (the master list) could look something like this:
<a ng-repeat="post in blog.posts" ui-sref="blogs.edit({postId: post.Id})">{{post.title}}</a>
<div ui-view></div>
This will render a list of anchor tags, and a nested details view under.
Related
I currently have a generic list component and I want to add, depending on where I use it, different callbacks for adding/removing/updating items to that list.
My current implementation looks like this:
<div list-callback1>
<generic-list
add-callback="listCallback1.add()"
update-callback="listCallback1.add(id, name)"
delete-callback="listCallback1.delete(id)"></generic-list>
</div>
My question:
Is there a way to decrease nesting? Because when I add the directive directly to my component I get a compile error.
Ok, it was a different problem.
I had scope: true in my list-callback1 directive.
After removing that, all works fine. Thanks for the help
Sorry I couldn't post more code, but I am restricted by my employer ;)
What I did is:
When a menu item is clicked, a action will be done, like deleting a user, sending emails to a group, etc. To this end, for each menu item, I define a ui-router state, and use the state url to activate the state via sref. I thought that a menu action is just a UI component for user to let users to do something, which is just a state of UI.
I was advised that I was using ui-router in a wrong way as a state url can not identify an action. For example, to delete a group of users, the state url can not tell you what group of users have been deleted.
In short, I agree with your manager while being an angular newbie myself. Angular routes are designed for managing different views of your app. I.e. define a route and corresponding view template for each view. If you add application logic into the routes, your application structure gets quickly a mess and difficult to keep clear.
To me it is much more natural that the views are managed by the routes, and each action in each view is handled by the controller of that view. If the actions grow "big", then it is worth refactoring parts of the controller into separate services. If you require some sort of "dynamic HTML" depending on the action, e.g. bootstrap modals are handy for doing that within the current view (see http://angular-ui.github.io/bootstrap/).
E.g. in my current project, I don't actually manually edit the routes at all but let yeoman angular generator to do that for me free of charge - i.e. I instantiate each new view in my dev.env using the following command (more info on this from https://github.com/yeoman/generator-angular)
yo angular:route myNewView
More info on angular philosophy can be read from angular documentation for developers: https://docs.angularjs.org/guide/concepts
You should probably be doing this actions via a method on $scope.
$scope.deleteItem = function (items) {
Service.delete(items);
};
// which is the same as:
$scope.deleteItem = Service.delete;
<a ng-click="deleteItem(item)">Delete This Item</a>
Having it in the URL just seems wrong. I mean what does that look like? www.mysite.com/delete/users?
I've just started trying out Marionette after building a couple of vanilla Backbone applications. Right out of the gate I'm running into some questions with region management and multiple collections.
I have the following nested Model and Collection structure
FoosCollection
FooModel
BarsCollection
BarModel
I want to take advantage of all the great views and layout/region managers that Marionette provides. However, I need to render this information on the page in a bit of a unique way. My HTML looks like this:
<div id="container">
<div id="foos-description"></div>
<div id="bars-list"></div>
</div>
Basically, some high level information from each of the FooModels needs to be rendered into the foos-description element. Then, each BarsCollection needs to be rendered into the bars-list. The structure needs to be such that the list is directly below the corresponding information in the foos-description container.
So, I would love to use CompositeViews to solve this, but it looks like the View/DOM element structure also needs to be nested in the same way that the collection/model structure is nested, which won't work in my case.
I've also added two Regions
App.addRegions({
foosDescription: "#foos-description",
barsList: "#bars-list"
});
My initializer code looks like this
App.addInitializer(function (options) {
App.foosCollection = new FoosCollection(options.foos, {bars: options.bars});
App.foosDescription.show(new FoosView({collection: App.foosCollection}));
App.foosCollection.each(function(f) {
app.barsList.show(new BarsView({collection: f.barsCollection}));
})
});
Obviously this will only show the last BarsCollection in the barsList region, but I'm unsure of how I should structure this such that each collection is appended to the region. Any help would be greatly appreciated.
You'll need to show the view in the region:
// tweaked region and view names for clarification
App.foosDescriptionRegion.show(foosDescriptionView);
There is chance that I might not be able to explain my problem properly. Let me try.
I am developing a single page application using angular. This app basically displays the episodes of an online novel series. There is a navigation bar, which has query menus (Like, latest episode, episode of a particular date, episodes with a particular tag, etc). For each of these queries, i want a separate url.
/latest - should display the latest episode
/tag/:tagname - should return all episodes with that tag.
For all these queries, the resultant view is the same (list of episodes). So I will be using the same partial for all routes.
My question is, Should I actually create a new controller for each query? like, LatestEpisodeController, TagController?
Is there anyway I can use the url to determine what the user wants and run that query from within the same controller?
Ofcourse you can use same controller in routing definition, the question is what is the purpose of that? It will be worse to debug it later, if you have a shared functionality it's better to turn it into a factory or service and then use in controllers.
But the answer is YES, you can use same controllers and implement different behaviour basing on i.e. $location.path()
yes you can use single controller for multiple routing..
you can create different functions in controller and in each function do the according job.
In my case I have created different html page for different url and registered same controller for the html pages and in the html page I have called controller method using ng-init in div portion.
You can use same controller and same views as you wish...
$location can help you to get current path or full url if you want and you can call your service depends on your path...
here I write a little example for you to get the idea
PLUNKER
I am looking for a bit of direction I am still fairly new to Backbone and am currently creating a test application to learn more.
My problem is this, I am populating a backbone view with a underscore template. I load a collection of models, then I find the model I need and populate these values into the template. There can be many pages based on the template so I have a dynamic route that accepts an id.
My problem is I want to add a next feature, that would change the current page and reload the template with the new model.
I have tried a crude method along the lines of :
Backbone.history.navigate(newLocation)
However this did'nt work, please note newLocation is actually populated with the route and the id I want to navigate to.
I will add some code from my view below, I won't include the full code however if it is needed please ask.
Any help or a push in the right direction would be great.
Thanks in advance
You need to use your router object's navigate method rather than than history's class method, and you need to pass it the option `{trigger: true} in order to invoke the corresponding route function.