Hi,
Since you are trying to force a digest cycle using

scope.$apply(function() {
      scope.states = data;
});

It is throwing an error saying it is not necessary to call $apply(). Add
just *scope.states = data;* and try again.
You would typically want to use $scope.$apply() only when you are trying to
make AJAX requests outside Angular context.


On Fri, Mar 7, 2014 at 12:08 AM, [email protected] <[email protected]>wrote:

> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Regards,
Aadithya C Udupa

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to