Hi,
I am a long time ASP.Net Developer, right now I have my own developed CMS, and the way I created the Admin is to be a single page Application utilizing the following:
-Kncokout.js
-Hisory.js
-Jquery.js
-and a lot of jquery plugins to handle, querystring, url and some nifty UI stuff, like select2, Redactor.js, etc...
Now my current structure lies around Modules, meaning that I have Blog Module, Gallery Module, and Newsletter Module etc…
Each Module has it is own, business logic, settings and Database structure as any other project, and I enable options per client through configuration class for each module.
The way I load the UI is that I use ASP.Net MVC razor Partial Views and I send them as JSON string using Jquery AJAX and ASP MVC Controller and then utilizing Jquery I just fill the Module Container Div with the JSON Result.
The benefit of this approach is that with Razor Views I can have great control and flexibility over the UI Logic. for example if user do not have access permission to add record, I can disable the rendering of Add Button in Razor before it reaches the browser, also I can fill Countries, and other Dynamic Drop down lists on the fly.
On Data binding side Knockout does all the work and it is great, but after I got introduced to Angular.js I was blow away by the natural feel of Data binding and the elegance of the frame work and wealth of other built in functions like routing, AJAX, etc…
Right now, I want to shift my code to Angular.js. However, I am confused and would appreciate it if someone could help on the following:
-Angular.js can load Views from normal HTML files, this is great, but as I mentioned above I will lose the ability to do complex Business logic and showing/hiding pieces of code to user on server side. So should I keep using Razor views to accomplish what I need, and load the views from server side, or is there something better?
-another problem I am having with Angualr.js is that it cashes views, and this makes it troublesome when I update the html and upload new version to server, not to mention permission issues if I change them.
-another problem I am having with Angular.js right now is that it does not lazy load controllers, directives, etc… and the way I am developing right now is that I load JavaScript logic required files with each razor view, this safes user bandwidth and make code grouped better, because not all pages use or have the same requirements. Again this will not work with angular, in other words I want to load controllers, directives, filters when they needed.
Overall, I am tired of knockout.js hacks to make things work and endless Dom manipulations, which were Angular.js Shines, but at the same time, I love the ability to makes business decisions on the server side in the views, so I need some guidance.
Sorry if my post is long or not descriptive enough but this seemed the best place to acquire some knowledge about best practices with Angualr.js before I make this huge shift.
Thanks in advanced.
Hi again,on help on this please ?
On Friday, May 17, 2013 4:55:02 AM UTC+4, dev mondo wrote:Hi,
I am a long time ASP.Net Developer, right now I have my own developed CMS, and the way I created the Admin is to be a single page Application utilizing the following:
-Kncokout.js
-Hisory.js
-Jquery.js
-and a lot of jquery plugins to handle, querystring, url and some nifty UI stuff, like select2, Redactor.js, etc...
Now my current structure lies around Modules, meaning that I have Blog Module, Gallery Module, and Newsletter Module etc…
Each Module has it is own, business logic, settings and Database structure as any other project, and I enable options per client through configuration class for each module.
The way I load the UI is that I use ASP.Net MVC razor Partial Views and I send them as JSON string using Jquery AJAX and ASP MVC Controller and then utilizing Jquery I just fill the Module Container Div with the JSON Result.
The benefit of this approach is that with Razor Views I can have great control and flexibility over the UI Logic. for example if user do not have access permission to add record, I can disable the rendering of Add Button in Razor before it reaches the browser, also I can fill Countries, and other Dynamic Drop down lists on the fly.
On Data binding side Knockout does all the work and it is great, but after I got introduced to Angular.js I was blow away by the natural feel of Data binding and the elegance of the frame work and wealth of other built in functions like routing, AJAX, etc…
Right now, I want to shift my code to Angular.js. However, I am confused and would appreciate it if someone could help on the following:
-Angular.js can load Views from normal HTML files, this is great, but as I mentioned above I will lose the ability to do complex Business logic and showing/hiding pieces of code to user on server side. So should I keep using Razor views to accomplish what I need, and load the views from server side, or is there something better?
-another problem I am having with Angualr.js is that it cashes views, and this makes it troublesome when I update the html and upload new version to server, not to mention permission issues if I change them.
-another problem I am having with Angular.js right now is that it does not lazy load controllers, directives, etc… and the way I am developing right now is that I load JavaScript logic required files with each razor view, this safes user bandwidth and make code grouped better, because not all pages use or have the same requirements. Again this will not work with angular, in other words I want to load controllers, directives, filters when they needed
Overall, I am tired of knockout.js hacks to make things work and endless Dom manipulations, which were Angular.js Shines, but at the same time, I love the ability to makes business decisions on the server side in the views, so I need some guidance.
Sorry if my post is long or not descriptive enough but this seemed the best place to acquire some knowledge about best practices with Angualr.js before I make this huge shift.
--
Thanks in advanced.
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
You can serve flat templates (rendered by razor) if you wish, but this is a clunky way, you you will lose all dynamic data updating. Serving data as a seperate asset (JSON) and rendering client side is much more flexible.-another problem I am having with Angualr.js is that it cashes views, and this makes it troublesome when I update the html and upload new version to server, not to mention permission issues if I change them.
I add a cache killer - ?cache={{killer}} - then $scope.killer = Math.floor(Math.random() * 1000);to every request. Define the killer in the top level controller and it is available in all templates. It will change on page refresh (which isnt THAT often in angular) - any better solutions welcome
Any help on this matter please ?
On Friday, May 17, 2013 4:55:02 AM UTC+4, dev mondo wrote:
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
@Rob and Alec, this is really really great advice from you guys as fellow ASP.Net Developersit is truly a mind-shift and steep learning curve but it is really feeling better than Knockout, really better!, i will follow your suggestions thoroughly.but if you could kindly advise on the following i would totally appreciate itthe �business logics i need are as follows-for example i have Languages list that is defined in static class in c#, right now what i do is in razor i show allowed languages based on the logged in user permission, this is easy as i have c# static method that i can call from Razor and it will return those allowed languages, but now with Angualr.js only i don't know how to do it, the only way i see for such a thing is make ajax calls after view loads to achieve the same thing, please correct me on that.-the other thing is as i mentioned before, i prevent a user to see some form fields based on his permissions-i have multi lingual app and based on user saved settings stored in db, if he chooses right to left language, i add ".rtl" class to document, Body again this is easy by calling a c# mthod from razor that in return calls db and return user's perferred language�so all in all what is the right way to achieve this with Angualr
On Thursday, May 23, 2013 7:34:12 PM UTC+4, Ron Buchanan wrote:
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/ypr5GSliXas/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
�
�
Alec,�
much appreciated your input, and you enlightened my mind on new way of thinking, all in all i see that i have to shift my own thinking to Angular first then Server when needed.on the security part, i see that the right solution is to have Server Validation and ViewModel that depends on User's permissions.
the biggest issue for me here, is to find a way to send these Application parts like Countries List, Languages list with each controller alongside the Model itself without repeating myself�
Mondo,
��� Since you would most likely not be doing a true SPA, I'll explain how I perform a "section" / page load. I work on very large enterprise applications, from billing systems to healthcare, so in many cases a true SPA is not practical. In these cases, I try to break down the application into one or more Angular Applications. Yes, you can have more than one Angular Application (even in the same page).
Within each of these "sections" as I like to call them, they are generally initiated by a single ASP.NET MVC view. When the view loads, it is loading the ng-app, which uses routing (angular, not asp.net mvc) to load the initial view into the ng-view. When that controller gets loaded, it makes a call via $http to a ServiceStack end point (or controller action) that returns what the controller (ng-controller) to function. The payload being returned from the server side is JSON.
Here is how I would handle it:
- Languages - That static method you are calling in razor is a classic example of how not to do it. Your controller already knows who the user is, so your View Model should've had a list of SelectListItems that represented the languages that the user could see.
When you do it in Angular, you would use that paradigm. In the server method that delivers your initial angular controller payload, the model it returns should have a value that represents those languages as an array of json objects. Your angular view would have a drop down tied to those.
- Form Fields on Permissions - You'd do this very similarly to the languages, pass the user permissions back in the initial payload to the controller. Then use ng-show="methodOnControllerScope(model.permissions)" on the form fields. This might not be the most secure way, but it is a starting point that you can build from. Biggest thing here is not allowing the user to modify those permissions.
- Same as above. In this case, I would have a root controller that manages the overall application stuff (menus, navigation, etc). You would have a property on the controllers model that would represent currentLanguageFormatting and now have ng-class="currentLanguageFormatting" on your <body> tag. When they select a language that is RTL, just set that property to "rtl".
The thing you need to keep in mind is that you have to give Angular controllers what it needs. This is no different than razor, as you would be passing a view model. Now you are just passing this to the controller.
ServiceStack is like WebAPI except that it doesn't feel like smashing yourself over the head with a brick.
On Tuesday, 4 June 2013 15:24:23 UTC+1, dev mondo wrote: --
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/ypr5GSliXas/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
On Tue, Jun 4, 2013 at 5:17 PM, Alec Whittington <alec.whi...@gmail.com> wrote:
Mondo,
Thanks for the kind words. I enjoy helping when I can.
ServiceStack make making a Restful API much simpler than Web Api. As Glenn Block has pointed out, the Web Api was never designed to be "RESTful", it was designed to be a layer over HTTP. With that comes extra work that must be done to make things work, even for a simple problem. ServiceStack as provides other added functionality out of the box, Caching and Session are two as is one of the fastest JSON Serializers for .NET.
I choose to use ServiceStack to interface with all AJAX requests from the browser as all I ever return is either JSON or a web request error with a status code. I like how I have clearly separated Request and Response objects as I've worked with the concepts of FormModels (Request Objects) and ViewModels (Response Objects) for years. It fits into my way of thinking already. I've also been using AttributeRouting with ASP.NET MVC for years and like how ServiceStack can make use of similar Attributes for declaring the service endpoints (routes).--
Thanks,
Alec
<compose-unknown-contact.jpg>
Tuesday, June 04, 2013 7:24 AM