Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ng-view>
- <viewer doc="getDocument()">
- </viewer>
- </ng-view>
- angular.directive('viewer', ['$compile', '$anchorScroll', function($compile, $anchorScroll) {
- return function(scope, element, attrs) {
- scope.$watch(
- function(scope) {
- var doc = scope.$eval(attrs.doc);
- if (!doc)
- return ""
- return doc.html;
- },
- function(value) {
- element.html(value);
- $compile(element.contents())(scope);
- }
- );
- };
- }]);
- angular.directive('i18n', ['$rootScope', 'LocaleService', function($rootScope, LocaleService) {
- var cleanup;
- return {
- restrict: 'EAC',
- compile: function(element, attrs) {
- var originalText = element.text();
- element.text(LocaleService.getTranslation(originalText, attrs.locale));
- cleanup = $rootScope.$on('locale-changed', function(locale) {
- element.text(LocaleService.getTranslation(originalText, attrs.locale || locale));
- });
- },
- link: function(scope) {
- scope.$on('$destroy', function() {
- console.log("destroy");
- cleanup();
- });
- }
- };
- }]);
- angular.directive('i18n', ['$rootScope', 'LocaleService', function($rootScope, LocaleService) {
- return {
- restrict: 'EAC',
- link: function(scope, element, attrs) {
- var cleanup;
- var originalText = element.text();
- element.text(LocaleService.getTranslation(originalText, attrs.locale));
- cleanup = $rootScope.$on('locale-changed', function(locale) {
- element.text(LocaleService.getTranslation(originalText, attrs.locale || locale));
- });
- scope.$on('$destroy', function() {
- console.log("destroy");
- cleanup();
- });
- }
- };
- }]);
- angular.directive('i18n', ['$rootScope', 'LocaleService', function($rootScope, LocaleService) {
- return {
- restrict: 'EAC',
- link: function(scope, element, attrs) {
- var originalText = element.text();
- setElText();
- function setElText(locale){
- element.text(LocaleService.getTranslation(originalText, attrs.locale || locale));
- }
- scope.$on('locale-changed', setElText);
- }
- };
- }]);
- $rootScope.$broadcast('locale-change', 'en-AU');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement