0

I'm trying to write a simple directive that allows the user to edit a certain variable, but when i try to update the parent variable it doesn't work.

this is my html:

<p class="scene-field-name editable-name" editable="foo"> {{foo}} </p>

and the directive:

myApp.directive('editable', function ($window, $compile) {
    return {
        restrict: "A",
        template: '<div class="editable-value" ng-hide="editorOn">{{value}} <a class="edit-a" ng-click="editorOn = true">edit</a></div>' +
'<div class="editable-editor" ng-show="editorOn">' +
    '<input type="text" value="{{tmpValue}}" />' +
    '<a ng-click="setValue()">OK</a>' +
'</div>',
        scope: {
            value: "=editable"
        },
        controller: function($scope) {
            $scope.tmpValue = $scope.value;
            $scope.editorOn = false;

            $scope.setValue = function () {
                $scope.value = $scope.tmpValue;
                $scope.editorOn = false;
            }
        }
    };

here it is in jsfiddle: http://jsfiddle.net/4srx2z0c/2/

you can see that when clicking OK it doesn't save the value back in the parent scope...

1 Answer 1

2

You don't bind the input to tmpValue. Instead of <input type="text" value="{{tmpValue}}" /> you should have <input type="text" ng-model="tmpValue" />.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.