I'm trying to set states variable from a directive but I get the error as title said, this is the code I made:
app.directive('country', ['$http', function($http) {
return {
restrict: 'C',
link: function(scope, element, attrs) {
element.change(function() {
$http.get(Routing.generate('states') + '/' + element.val()).success(function(data) {
if (data.message) {
scope.message = data.message;
} else {
scope.$apply(function() {
scope.states = data;
});
}
console.log(scope.states);
}).error(function(data, status, headers, config) {
if (status == '500') {
scope.message = "No hay conexión con el servidor.";
}
});
});
}
}
}]);
What's wrong?
ReynierPM
Mobile: +58 424-180.56.09