The site that I'm working on has a custom CMS, and I'm using angularjs for inline page editing. The database stores HTML used to generate the pages, so I can't strictly use client-side templates and models.
I'm not using HTML5 pushState, so the URLs are like example.com/page#/widget/1/edit or example.com/page#/widget/new, and my current issue is that when I submit a form to edit a widget or add a widget, then I want the page to reload its content via injecting HTML into the DOM and change the URL to the default, which I'm trying with $location.path('/')
.
My current implementation has multiple issues (which you'll see in the demo), one of which is that in my form submit()
callback, changing $location.path
only changes the URL on a second form button click. I also try to change the URL which I click 'Delete', and that doesn't work either.
customPage.controller('PageEditCtrl', function($scope, $http, $routeParams, $location, $route, $compile, PageState) {
var widgetId = $routeParams.id || widgetCount + 1;
$scope.pageState = PageState;
$scope.widget = { id: widgetId, name: 'Widget ' + widgetId };
$scope.submit = function() {
if ($scope.widget.id > widgetCount) widgetCount += 1;
setTimeout(function() {
var element = $compile(genHtml())($scope);
angular.element('#page-content').html(element);
$location.path('/');
}, 100);
};
});