I am trying to design a angularcrud application where I can notify other users if an object has been updated. I have been reading a little bit about broadcasting and watchers. Just no idea where to place the code that handles all this? Should I implement a singleton messageservice that is injected in all my modules/controllers that handles this? Anyone experience with this?
I built a custom notification module. I made a module that has a directive and a singleton service like you said.
I'll share it with you:
https://github.com/breck421/angular-notifications/blob/master/NotificationModule.js
Let me know if you have any questions.
Thanks,
Jordan
Related
Currently am writing all my business logic inside the view class which make my view class unmanageable. Am planning to create Backbone object and move all the business logic there and invoke it from view class. Please correct me with right way of thinking
Backbone in general does not provide an entity named Controller, this is one of the reasons which Backbone called MV*. Generally user interact with views, you know well this interact means change and update over models.
"So does Backbone.js have controllers? Not really. Backbone’s views typically contain
controller logic, and routers are used to help manage application state, but neither are
true controllers according to classical MVC." (Addy Osmani Book's)
so i think your way is not incorrect, but you can improve your project structure through this solutions:
Marrionette (and also Thorax ) is a excellent framework that provide such a excellent structure for your app. You can read this annotated code and get some tip from it.
You know certainly AMD a nice api to provide modular pattern in js. Require.js a nice tool for organize your code. For more information i recommend check TodoMVC + Backbone+Require code.
I have a general question. I've recently seen plenty of examples of people putting all their directive logic in a directive controller (and using it with controllerAs) instead of using link. I do see certain benefits in that:
The directive logic can be easily unit-tested.
You are seamlessly obligated to use the "dot notation" in your view model, thus prevent unexpected behavior.
As for the disadvantages - once the logic is inside the controller, it is exposed to other directives, as if encouraging developers of other directives to access those variables/methods, even if they are not meant to be accessed from outside.
I am interested in getting your take on this? How do you organize your code inside the directive.
Thanks
I am using Angular for about 4 months so I cannot
Say that I have too much experience. However in my
Personal experience I used the controller only for logic
That needs to be shared or executed before the link
Function. I guess you can hide some logic from your controller by using the module pattern and only exposing the logic that is really necessary. In my defense I haven't wrote really complicated controllers but this is the way I would go. (Sorry for my bad writing I am responding from my phone)
I have an AngularJS 1.3 application that will I suppose eventually move to AngularJS 2.0. I've watched the videos from ng-europe and I understand there are many changes. As I expect development to continue with our AngularJS 1.3 code for the next 12 I would like to hear if anyone has any specific suggestions on preparing for 2.0.
My application is simple in that it creates no directives. In particular I would like to hear any tips on how I should go about creating controllers to get ready for them being very different in 2.0. Should I eliminate all references to scope in my controllers. Should I move everything to services?
I hope for some useful suggestions but of course specific ones so this question does not get closed.
Thanks
I think that so little has specifically been announced yet, and there's so much potential for it to change that it's a hard question to answer, e.g. check out this issue for an example of something quite fundamental that's likely to change since the ng-europe announcement.
Within my team we're trying to take the following approach:
Try not to use $scope (controller-as syntax).
Keep your controllers as light as possible by using directives to encapsulate UI functionality and services to deal with data models / API calls.
Use the new syntax for one-way binding where you don't need two-way binding. One-way binding will be the default for Angular 2.0.
Write some unit tests! It'll be much easier to do some significant refactoring if you have some confidence that your code will still work :).
Not only should that help with the move to 2.0 if / when that happens, but it should help your 1.3 apps too!
I'm developing some reusable components with AngularJS, I checked angular-ui/bootstrap to steal some ideas and best practices and I was surprised that they create one module per Bootstrap component.
https://github.com/angular-ui/bootstrap
Can anyone explain this? Should I follow this pattern in my project?
Because some people might need just one component, and not necessarily all of them.
If your project is going to be an open-source set of components, you can consider that approach. Otherwise, there's probably no need for it.
The recommended way of structuring a "normal", larger application would be to group things that share a view into a module. So you might have an admin module, messages module... each with its components.
I am developing a game in Silverlight. I have my game flow ready and graphics have also been taken care of. Now while searching for a perfect back-end design i came across MVVM. Went through various tutorials and have an understanding of how it would work with a single module. However in my plan i want to load/call multiple views at user input. Is there a way a single controller can handle my application workflow. It has been mentioned in the following post:
Controllers in MVVM, How to get info from viewmodel to it's controller?
But nowhere i could find an example. Can someone provide a dummy application, reading material, block diagrams?
You need to use framework to help what you're trying to do, otherwise you will end up write tons of code.
I have create similar application (show multiple view to user at a time) and I use Prism to help me. If you want to learn about it, you can walk through Prism Training Kit.