angularjs - Angular js using $rootScope in ng-src script on refresh fails -
i'm creating project internationalization, labels in /conf/lang/lang_{{lang}}/labels.js included in index.html. lang - rootscope variable setting in app.run(). index.html
<script ng-src="{{labelurl}}"></script>
app.js - run()
$rootscope.$on('$locationchangestart', function (event, next, current) { if($cookiestore.get("config_details") != undefined) { $rootscope.language = $cookiestore.get("config_details").language; } else { $rootscope.language = 'english'; } $rootscope.labelurl = "conf/lang/lang_"+$rootscope.language+"/labels.js"; })
this script file loading correctly on url changing when refresh manually $rootscope value destroys , script file loading after html content loaded. me resolve this!!!
yes when try reload page destroyed. @ this
var myapp = angular.module('myapp', ['ngcookies']); myapp.controller('maincontroller', ['$scope', '$rootscope', '$cookies', '$timeout', function($scope, $rootscope, $cookies, $timeout) { if ($cookies.get('lang')) { $scope.debug = "browser has got cookies"; $rootscope.language = $cookies.get('lang'); } else { $scope.debug = "browser not have cookies"; $timeout(function() { $cookies.put('lang', 'en'); $rootscope.language = 'en'; $scope.debug = "browser has got cookies"; }, 2000); } }]);
Comments
Post a Comment