Blackbaud-BobbyEarl / hacker-backer

A repo to test hackathon concepts.
0 stars 0 forks source link

AngularJS Tips #5

Open Blackbaud-BobbyEarl opened 8 years ago

Blackbaud-BobbyEarl commented 8 years ago
Blackbaud-BobbyEarl commented 8 years ago

I think almost every action in the site should have an appropriate state. I think this better supports deep linking. One complication I got from this was how to open modals via a state. Here's an example...

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-open-a-dialogmodal-at-a-certain-state

Blackbaud-SteveBrush commented 8 years ago

For the "Go back" method, I've used this in the past. Not sure if it's the best way, but seemed to do the job.

app.run(['$rootScope', '$location', function ($rootScope, $location) { var history = []; $rootScope.$on('$routeChangeSuccess', function() { history.push($location.$$path); }); $rootScope.back = function () { var prevUrl = history.length > 1 ? history.splice(-2)[0] : "/"; $location.path(prevUrl); }; }]);

Blackbaud-SteveBrush commented 8 years ago

Is this the preferred directive/controller setup? Obviously the replace/restrict properties could be changed to fit the scenario.

screen shot 2015-08-22 at 10 10 33 am