I am facing an issue while trying to pass information through a view in a directive. Despite binding the scope, I keep seeing the string value 'site._id' instead of the actual value.
Below is the code for the directive:
angular.module('app')
.directive('anomalieTableau', function () {
var controller = ['$scope', '$attrs', 'srv_traitementsSite', function ($scope, $attrs, srv_traitementsSite) {
$scope.anomalies = [];
var idSite = $attrs.idsite;
alert(idSite);
var idAgence = $attrs.idagence;
var dateDebut = $attrs.datedebut;
var dateFin = $attrs.datefin;
var promise = undefined;
if (idAgence && idSite) {
promise = srv_traitementsSite.TraitementSiteAgenceAnomalie(idSite, idAgence, dateDebut, dateFin);
}
promise.then(function (response) {
$scope.anomalies = response.data;
}, function (response) {
});
}];
return {
restrict: 'EAC',
templateUrl: 'tpl/directive/AnomalieTableauDirective.html',
controller: controller,
scope: {
idsite: '=',
idagence: '=',
datedebut: '=',
datefin: '='
}
};
});
Here's how the directive is called in HTML:
<div anomalie-tableau idsite="site._id" idagence="AgenceId" datedebut="dateDebutStats"
datefin="dateFinStats" class="col-md-12"></div>
The alert result in the directive is showing 'site._id' instead of the expected value '123456789'.
Upon editing 'site._id' to {{site._id}} in the attribute directive's call, it triggers an error:
Syntax Error: Token 'site._id' is unexpected, expecting [:] at column 3 of the expression [{{site._id}}] starting at [site._id}}].
I'm unsure what mistake I'm making. Can anyone provide insights?