javascript - AngularJS Trigger $scope.broadcast from $resource -
INTRODUCTION
I am trying to ensure that all parts of my angular application I am using correctly / all correct codes are in the right place
I came to this article in which there is an example application with data stored in an array inside the service. I think the way The app is structured from, it makes sense (but may be completely wrong).
Question
Do I start the $ $ resource in the same way when I update the ARAR in this code, then I have a $ broadcast trigger.
Here is a planner of an example job p>
bonus question h2>
if I can strong> which I If I do, then the second question should strong> me? I take the place in the conversation with the all strong> service (and $ resource in that) controller (which I have not done so far) p> Any ideas or suggestions will be highly appreciated . P> div> Yes, whatever you are asking can do it. A In the success / failed handler, you do the Edit strong> p> Here is a full service implementation. Note that you can make this cat skin in many ways, so these are just a few example ideas. P> Should you do this? Strong> p> I do not see too much damage in doing this, but you should at least give it something you thought you would This event will send an event in such a scope that does not care about the event at all. Keep in mind that there are many scopes in your app (created by administrators / instructions). There is probably no big deal in most cases. P> The good thing about $ resource code> will return an object / array which is
$ promise code> property. You can promise to ask that when the server's request is successful / fails. P>
$ rootScope. There is a service using the
query () code> method of
$ resource code> to do this as needed for transmission () code>: p>
myApp.service ('book', function ($ rootscope, $ resource) {var myResource = $ resource ('/ books /: id', {id: 'id'}); Var books; var service = {// This result returns results: function () {myResource.query (function) {$ rootScope $ broadcast ('this. Work', response);}, function (error) {$ Rootscope. $ Broadcast ('it.failed', error);});}, // This function gives $ resource and also holds a copy // someone else can get getbooks Gath data () getBooks2: function () {books = myResource.query (); Books. $ Promise (function) (feedback) {// If you still need to broadcast ... $ Rootscope. $ Broadcast ('this. Work ');}, function (error) {$ Rootscope. $ Has been broadcasted (' it.failed ');}); return books;}, getBookResult: function () {return books;}} return service ;}); Code> pre>
$ broadcast () code> the scope of your application hierarchy P>
$ resource code> is that it gives you an empty object, which is then filled with server response, so many times you can use the Reservation Resort is not needed :) Scenes that use the value of the resource, will be automatically updated. And the value (or error) needed for the controller can be used from
$ promise code> to
$ resource code> as I have shown above. P> div> HTML>
Comments
Post a Comment