Copied to clipboard

Flag this post as spam?

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


  • iNETZO 133 posts 496 karma points c-trib
    May 13, 2020 @ 15:23
    iNETZO
    0

    angular.element('form[name=contentForm]').scope() undefined only in production

    Hi,

    I'm creating a Content App which is only usable if the document is saved. I've created a controller using:

        var contentForm = angular.element('form[name=contentForm]').scope().contentForm;
    
        $scope.$watch(function watch(scope) {
            return contentForm.$dirty;
          },
          function handle(newValue, oldValue) {
              vm.ContentSaved = !newValue;
         },
         true);
    

    This works great in developmentmode but when the site is publised to our production environment, the follow error is show in the console:

    "angular.element('form[name=contentForm]').scope(...) is undefined"
    

    The differcence between development and production is it's using DependencyHandler.axd

    What can be a reason that the angular.element('form[name=contentForm]').scope() not exists when using the DependencyHandler?

    Best regards,

    iNETZO

  • Pagggy 28 posts 71 karma points
    Jun 19, 2020 @ 08:45
    Pagggy
    0

    Hi @iNETZO, I think this issue is regarding https://github.com/angular/angular.js/issues/9515

    did you came across solution to this problem? we are having same issue too.

  • iNETZO 133 posts 496 karma points c-trib
    Jun 19, 2020 @ 09:55
    iNETZO
    0

    Hi Pagggy,

    In my case i only wanted to know if the form was dirty. I changed the code to this:

    var contentForm = angular.element('form[name=contentForm]');
    
    $scope.$watch(function watch(scope) {
        return contentForm.attr('class');
    },
        function handle(newValue, oldValue) {
    
            var isDirty = newValue.includes("ng-dirty");
    
            vm.ContentSaved = !isDirty;
    
            if (editorState.current.id == 0) {
                vm.ContentSaved = false;
            }
    
        },
        true
    ); 
    

    Maybe not the best method, i don't like watches but i was under time pressure.

Please Sign in or register to post replies

Write your reply to:

Draft