I am doing a form with inline editing. I found an example here: https://stackoverflow.com/a/16739227/169252
which I adapted to my needs. Here's some of the code (using nodejs, express and jade). The directive:
// Inline edit directive
app.directive('inlineEdit', function($timeout) {
return {
scope: {
model: '=inlineEdit',
handleSave: '&onSave',
handleCancel: '&onCancel'
},
link: function(scope, elm, attr) {
var previousValue;
scope.edit = function() {
scope.editMode = true;
previousValue = scope.model;
$timeout(function() {
elm.find('input')[0].focus();
}, 0, false);
};
scope.save = function() {
scope.editMode = false;
scope.handleSave({value: scope.model});
};
scope.cancel = function() {
scope.editMode = false;
scope.model = previousValue;
scope.handleCancel({value: scope.model});
};
},
templateUrl: 'partials/inline-edit'
};
});
The controller:
myControllers.controller('MyCtrl', ['$scope', '$http',
function MyCtrl($scope, $http) {
$scope.name = "Name";
$scope.surname = "Surname";
$scope.email = "Email";
$scope.save_user = function() {
//What do I do here??
};
The template for the directive ('partials/inline-edit
'):
div(class="inline_edit_div")
input(class="inline_edit_input" type="text" on-enter="save()" on-blur="cancel()" on-esc="cancel()" ng-model="model" ng-show="editMode")
span(ng-mouseenter="showEdit = true" ng-mouseleave="showEdit = false")
span(ng-hide="editMode" ng-click="edit()")
div(class="inline_edit_text")
{{model}}
And the form itself:
div(ng-controller="MyCtrl")
form(id="user_form")
div.inline.action_buttons
button(class="buttons action_button" ng-click="save_user()") Save
div.info
div.element
label(class="form") Name
div.form(inline-edit="name")
div.element
label(class="form") Surname
div.form(inline-edit="surname")
div.info_element_bottom
label(class="form") Email
div.form(inline-edit="email")
My problem:
As suggested here,
How do I submit a form to a controller on the server?
I could, on submit, post the data accessing the $scope
, e.g. $scope.person
.
However, with the inlineEdit directive, I am creating inherited scopes - so I've not been able to figure out how to access my form data from my controller. https://stackoverflow.com/a/13428220/169252 says you can't access child scopes from a parent scope.
In short, how can I submit with $http the whole form (preferrably I'd like to understand how to do it without a conventional POST with whole page reload)? The $scope.save_user
in the controller gets called but from there I don't know any further.