question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling images upload with angular

See original GitHub issue

Hey guys, first thanks for this amazing inline editor.

I’ve included the editor in an angular webapp, using the following directive code :

 angular.module('editorApp', [])
    .directive('ngEditor',  function(){
        function link(scope, element, attrs){

            // Initialise the editor
            editor = new ContentTools.EditorApp.get()
            editor.init('[ng-editor]', 'ng-editor')

            // Bind a function on editor save
            editor.bind('save', function(regions, autoSave){

                scope.$apply(function(){
                    scope.regions = regions;
                });

                // "regions" contains all the html for each editable regions
                // Now, "regions" can be saved and used as needed.

            })

        }

        return {
            link: link
        }

    })

My problem is that I can’t upload images. I’ve tried to insert the blueprint code given on http://getcontenttools.com/tutorials/handling-image-uploads in this directive like so :

angular.module('myAwesomeAppToChangeTheWorld')
  .directive('ngEditor', function () {
    function link(scope, element, attrs){

            // Initialise the editor
            var editor = new ContentTools.EditorApp.get();
            editor.init('[ng-editor]', 'ng-editor');

            var imageUploader = function(dialog){
                console.log('DIALOG : ' + JSON.stringify(dialog));
                Materialize.toast('IMAGE DIALOG LOAD', 2000);

                dialog.bind('imageuploader.cancelupload', function () {
                    // Cancel the current upload
                    Materialize.toast('CANCELED', 2000);
                    // Stop the upload
                    if (xhr) {
                        xhr.upload.removeEventListener('progress', xhrProgress);
                        xhr.removeEventListener('readystatechange', xhrComplete);
                        xhr.abort();
                    }

                    // Set the dialog to empty
                    dialog.state('empty');
                });

                dialog.bind('imageuploader.clear', function () {
                    // Clear the current image
                    dialog.clear();
                    image = null;
                });

                dialog.bind('imageuploader.fileready', function (ev) {
                    console.log('FILE READY : ' );
                    Materialize.toast('FILE READY', 2000);
                });

                dialog.bind('imageuploader.save', function () {
                    console.log('FILE SAVE : ' );
                    Materialize.toast('FILE SAVE', 2000);
                });
            };

            ContentTools.IMAGE_UPLOADER = imageUploader;

            // Bind a function on editor save
            editor.bind('save', function(regions, autoSave){

                scope.$apply(function(){
                    scope.regions = regions;
                });

                // "regions" contains all the html for each editable regions
                // Now, "regions" can be saved and used as needed.

            });

        }

        return {
            link: link
        }
  });

I’ve replaced the “addEventListener” on dialog by the “bind” method, because when I use “addEventListener” it says “dialog.addEventListener is not a function”, whereas dialog is well defined. And now it just doesn’t work with “bind”.

So do you know where my problem come from ? Any idea ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jimmy4701commented, Aug 28, 2016

@anthonyjb Thanks for your help but I can’t give you an access to the code (company code). I just created a directive using the code I’ve pasted in my last posts (with editor.bind(‘save’) ).

Don’t worry if my problem persists. Unfortunately I had to change from ContentTools to another package, because of time.

Thanks for your help and for your time anyway. Hope the problem will still be an exception. And thanks for ContentTools which is a pretty good package (and which works on my other projects so …^^)

0reactions
anthonyjbcommented, Aug 26, 2016

@jimmy4701 sorry for the delayed reply - I’m a bit stumped now 😦

I’ve just looked back over your initial post and the code and I can see you’re using

// Bind a function on editor save
editor.bind('save', function(regions, autoSave) ...

If this is working then the wrong version of the library is definitely getting dragged in as bind doesn’t exist against the editor and that wouldn’t work it would just error. Since your getting to the point where the editor starts (e.g your issue is with uploading an image) I think this has to be a version issue.

Any chance you can give me access to or send me a complete example I can debug live?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Image Upload Made Easy - Academind
Uploading Images (or Files in general) in Angular apps isn't as hard as most people think. It's actually pretty simple and only involves...
Read more >
Angular 14 Image Upload with Preview example - BezKoder
Let's create Image Upload UI with Preview, Progress Bars, Card, Button and Message. ... The progress is variable for display upload progress of ......
Read more >
How to make image upload easy with Angular - freeCodeCamp
How to make image upload easy with Angular · 1. Create a template first · 2. Don't forget for Component Code · 3....
Read more >
Angular image upload tutorial - TinyMCE
Angular image upload is possible with TinyMCE as your app's rich text editor. Discover how to set up Angular image upload in your...
Read more >
Angular File Upload - Complete Guide
The best way to handle file upload in Angular is to build one or more custom components, depending on the supported upload scenarios....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found