Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Initializing ace editor content using $http service #177

Open
prashant-pokhriyal opened this issue Aug 30, 2017 · 3 comments
Open

Initializing ace editor content using $http service #177

prashant-pokhriyal opened this issue Aug 30, 2017 · 3 comments

Comments

@prashant-pokhriyal
Copy link

I'm rendering content of the editor using $http service. But onLoad function is being called much before data is rendered in editor.

When I'm adding code inside $timeout service then it is working properly. Is there any way to achieve this without using $timeout service.

funciton onLoad(editor) {
   /*
     It will set the some of  the lines readyonly. But because onLoad is executing much 
     before data is rendered from $http service, it does not find any lines.
   */
   set_readonly_lines(editor);
}
funciton onLoad(editor) {
   /*
     Using timeout it is working properly
   */
   $timeout(function() {
      set_readonly_lines(editor);
   }, 1);
}
@augustoeliezer
Copy link

Store the editor from onLoad in $scope.

$scope.aceLoaded = function($editor) {

    $scope.$editor = $editor;
};

$scope.onOpen = function(code, fileExtension) {
    let mode = resolveExtension(fileExtension);
    $scope.html = code;
    $scope.$editor.session.setMode('ace/mode/' + mode);
}

@prashant-pokhriyal
Copy link
Author

Excuse me for my poor inferring, but I'm not able to get you

@augustoeliezer
Copy link

augustoeliezer commented Oct 24, 2017

Sorry I forgot add the service

$scope.openFile = function(file) {
    //Here I prefer use factory.
    //fileFactory.openFile(file).then(fn,fn);
    $http.post('/api', file).then(function (res) {
        $scope.onOpen( res.data.content, res.data.extension)
    },angular.noop);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants