Accéder au scope depuis un script
Bonjour,
J'aimerai pouvoir binder un ng-show sur un booleen, ou un retour de fonction.
Mais, mon ng-show est situé dans un <script type="text/ng-template" id="firstDialogId">.
Voici le code concerné :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <script type="text/ng-template" id="firstDialogId">
<div class="ngdialog-message" align="center" id="download">
<h4 ng-show="isFrench">Télécharger la cartographie</h4>
<h4 ng-show="getIsEnglish()">Download cartography</h4>
<a href="index.html" download>
<img src="../style/images/pdf-icon.png" alt="Download PDF" width="30%" height="30%">
</a>
<a href="index.html" download>
<img border="0" src="../style/images/vsd-icon.png" alt="Download VSD" width="30%" height="30%">
</a>
<a href="index.html" download>
<img border="0" src="../style/images/PNG-icon.png" alt="Download PNG" width="30%" height="30%">
</a>
<div class="ngdialog-buttons">
<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="closeThisDialog('button')">Close</button>
</div>
</div>
</script> |
J'essaie avec un booleen et également avec un getter tous deux issus du controller car il semblerait qu'on puisse accéder aux fonctions mais pas aux variables du $scope depuis un ng-template.
Et voici la partie concernée de mon controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| app.controller('viewerController', function ($scope, $rootScope, ngDialog) {
// Slide menu state
$scope.checked = false; // This will be binded using the ps-open attribute
$scope.toggle = function() {
$scope.checked = !$scope.checked
}
// Language initialization
$scope.defaultLanguage = navigator.language || navigator.userLanguage;
if (localStorage.getItem("defaultLanguage"))
$scope.currentLanguage = localStorage.getItem("defaultLanguage");
else
$scope.currentLanguage = $scope.defaultLanguage;
if ($scope.currentLanguage == "fr") {
$scope.isFrench = true;
$scope.isEnglish = false;
}
else if ($scope.currentLanguage == "en") {
$scope.isFrench = false;
$scope.isEnglish = true;
}
$scope.getIsFrench = function () {
return $scope.isFrench;
};
$scope.getIsEnglish = function () {
return $scope.isEnglish;
}; |
J'ai également essayé :
Code:
1 2 3 4
|
<h4 ng-show="angular.element(document.getElementById("svgElement")).scope().isFrench">Télécharger la cartographie</h4>
<h4 ng-show="angular.element(document.getElementById("svgElement")).scope().isEnglish">Download cartography</h4>
... |
ou encore :
Code:
1 2 3 4
|
<h4 ng-show="angular.element(document.querySelector('#french')).innerHTML">Télécharger la cartographie</h4>
<h4 ng-show="angular.element(document.querySelector('#english')).innerHTML">Download cartography</h4>
... |
Mais aussi :
Code:
1 2 3 4 5 6 7 8 9
| <!-- This should be hidden -->
isFrench : <div id="french">{{ isFrench }}</div>
isEnglish : <div id="english">{{ isEnglish }}</div>
<script type="text/ng-template" id="firstDialogId">
<div class="ngdialog-message" align="center" id="download">
<h4 ng-show="document.getElementById('french').innerHTML">Télécharger la cartographie</h4>
<h4 ng-show="document.getElementById('english').innerHTML">Download cartography</h4>
... |
Enfin, rien de tout ça n'a fonctionné, une idée du pourquoi et de comment résoudre mon problème ?
Amicalement.