I have a post request in angularjs that get's a string pattern from my 
backend:

var tabledata = "";
> $http.post("lib/action.php", {monsters: 
> $scope.getMonsters}).success(function(data) {   
>     tabledata = data;   //Assign the pattern
> }).error(function(data) { console.log("error"); });
>
>

The thing I want to accomplish is that I want my directive to execute AFTER 
that the post request has been completed, because now when I run my 
application, the tabledata is just an empty string, and therefor, my 
makeTableFrom function is returning an empty result.

Here is my directive:



> gameApp.directive('mapActivity', function() {
>     return {
>         restrict: 'A',
>         link: function(scope, element, attrs) {
>             scope.$watch('tabledata', function() {
>
>              angular.element('.click#1').addClass('dotted').html($("<img 
> src='images/dot.png'>"));          
>                 var j = null;
>                 for(var i = 1; i <= 4; i++)
>                 {
>                     $.ajax({
>                         type: 'GET',
>                         url: 'lib/terrain.php',
>                         dataType: 'html',
>                         data: {i: i},
>                         success: function(data) {
>                             var randomRuta = Math.floor((Math.random() * 100) 
> + 1);
>                             
> angular.element('.click#'+randomRuta).addClass('monster').html($("<img 
> src='images/blackdot.png' title='"+data+"'>"));                  
>                         },
>                         error: function(xhr, ajaxOptions, thrownError) { 
> alert(thrownError); }
>                     });
>                     j=i;
>                 }  
>                 angular.element('.click').click(function() {
>                     if(angular.element(this).hasClass('monster'))
>                     {
>                         if(confirm('Vill du anfalla monster?'))
>                         {
>                             alert("Du vann");
>                             angular.element('.click.monster'+j).empty();
>                             
> angular.element('.click.monster').removeClass('monster'+j);
>
>                             angular.element('.click.dotted').empty();
>                             
> angular.element('.click.dotted').removeClass('dotted');
>                             angular.element(this).addClass('dotted');
>                             angular.element('.click.dotted').html($('<img 
> src="images/dot.png">'));
>                         }
>                     }
>                     else
>                     {
>                         angular.element('.click.dotted').empty();
>                         
> angular.element('.click.dotted').removeClass('dotted');
>
>                         if(!angular.element(this).hasClass('dotted'))
>                         {
>                             angular.element(this).addClass('dotted');
>                             angular.element(this).html($('<img 
> src="images/dot.png">'));
>                         }
>                     }
>                 });
>             });                     
>         }
>     };});
>
>
 
 

-- 
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