Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 31, 2014 @ 18:15
    Dave Woestenborghs
    0

    Angular : how to get item name changes

    Hi,

    I'm creating a property editor and would like to fire a function when the user changes the name of the item currently being edited. I tried to do $scope.$watch but that doesn't seem to be working:

    Here is my controller code :

    angular.module("umbraco")
        .controller("MyPropertyEditorController",
        function ($scope, editorState) {
    
            $scope.model.value.myprop = editorState.current.name;
    
            $scope.$watch('editorState.current.name', function() {
                $scope.model.value.myprop = editorState.current.name;
            });
        });
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 31, 2014 @ 20:49
    Dave Woestenborghs
    104

    I found out how to do it :

    I added the editor state to the scope and then it works fine

    angular.module("umbraco")
        .controller("MyPropertyEditorController",
        function ($scope, editorState) {
    
            $scope.editorState = editorState;
            $scope.model.value.myprop = $scope.editorState.current.name;
    
            $scope.$watch('editorState.current.name', function(newVal) {
                $scope.model.value.myprop = newVal;
            });
        });
  • Dmitriy 168 posts 588 karma points
    Jan 23, 2019 @ 17:10
    Dmitriy
    0

    Sorry for necrocommenting, but I have a similar problem with that. When you adding the editorState to scope its invokes so many times and it bother me a liitle, it is possible edditorState disturbing database so many times.

    What do you think about it?

Please Sign in or register to post replies

Write your reply to:

Draft