0

I have a task to store a model value in my Electron Angular project . The rootscope model is binding the file path value .

I want to save this path on my project and every time when user will open this app by default it will be present there

$rootScope.Path = user_path[0];

I want to save this $rootScope.Path and make the data persist on that location everytime.

Any way to achieve this in electron/node.js ?

EDIT:-

$rootScope.fPath = "C:\\";

    /*Configure FILE path*/
    const {dialog} = require('electron').remote;
    $scope.getFile = function(){
        var file_path = dialog.showOpenDialog({
            properties: ['openDirectory']
        });
        console.log(file_path);

        $rootScope.fPath = file_path[0] + "\\bin";

I want to make this $rootScope.fPath path persist whenever I will open my app the previous selected path must be there already. So that I don't have to make further changes.

WhoAmI
  • 217
  • 1
  • 2
  • 23

1 Answers1

0

having a code snippet helps... is this what you're looking for ??

   

      var app = angular.module('myApp', []);
        
      app.run(function($rootScope) {
        $rootScope.fpath = 'http://someSite/someFile';
      });
      
      app.controller('myCtrl', function($scope, $rootScope) {
        
        console.log("fpath:" + $rootScope.fpath);

        $scope.getFile = function(){
          var file_path = dialog.showOpenDialog({
              properties: ['openDirectory']
          });
        }

      });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<div ng-app="myApp">
    <p>The fPath as defined globally: <mark>{{fpath}} </mark></p>

    <div ng-controller="myCtrl">  
      <p>The fPath as when accessed in the controller: <mark>{{fpath}}</mark> </p>
    </div>

</div>
Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
  • So if I close my application or redirect to other page , do the declared file path will be there ? – WhoAmI Nov 16 '18 at 11:59
  • this is accessible inside the AngularJS single-page-application... even if you have a router and move around in the application, it should work – Akber Iqbal Nov 16 '18 at 12:23
  • Yes , I am doing this in Node/Electron way. I achieved this by using https://github.com/sindresorhus/electron-store – WhoAmI Nov 19 '18 at 07:03