Pass $ scope.variable to a javascript tagged in home

0

How to pass content within config to global variables:

//meu config
app.run(function(editableOptions, $rootScope, $filter) {
        editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
        $rootScope.$on('$routeChangeSuccess', function (e, current, pre) {
            var c = current.$$route.originalPath.length;
           $rootScope.action = current.$$route.originalPath;
        });
    });

In view I want to reset a variable within HTML, is it possible? The example below does not work:

<script>
var action = '{{action}}';
</script>

I tried this:

  //meu config
    app.run(function(editableOptions, $rootScope, $filter) {
            editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
            $rootScope.$on('$routeChangeSuccess', function (e, current, pre) {
                var c = current.$$route.originalPath.length;
               $rootScope.action = '<script> var action = "'+current.$$route.originalPath+'";</script>';
            });
        });

{{action}}

It also did not work.

    
asked by anonymous 15.03.2017 / 18:30

1 answer

2

You can use the window variable as global, you just have to pay attention when it is changed

In Javascript

var myApp = angular.module('myApp',[]);
window.test1 = 10;
window.test2;

myApp.controller('MyCtrl',['$scope',
  function MyCtrl($scope) {
    $scope.varA = test1;
    window.test2 = 'shared with window';
  }]
);

function myFunction() {
  alert(test2);
}

No Html

<div ng-app="myApp" ng-controller="MyCtrl">

 {{varA}}

<button onclick="myFunction()">Click me</button>

</div>

link

    
15.03.2017 / 19:17