AngularJs - directives do not work via ajax

0

I have a page: index.php and app.js . on my app I make a load to main.php which is the initial loading of the site. within main it will get select , div with ng-repeat , ng-source , etc.

But when main content was part of index it worked normal, but now it just does not work anymore loads the page, plus the directives: ng-repeat , ng-source , etc do not seem to work. I'll go through a snippet of code for you to see

app.js

var app = angular.module("MeuApp", []);
app.controller("MeuAppCtrl", function($scope, $http) {
$scope.msg = "Olá Usuários";
var carregarMain = function() {
    $http.get("http://localhost/main.php").success(function(data, status) {

        $("#mainPage").html(data);
        carregarBanner();
    });
};
var carregarBanner = function() {
    $http.get("http://localhost/banner.php").success(function(data, status) 

{
            $scope.banners = data;
            alert(data[0].foto);
        });
    };
    carregarMain();
});

index.php

<div id="mainPage"></div>

main.php

<div ng-repeat="banner in banners">
  {{banner.foto}}
  <div class="item">
    <img ng-src="{{banner.foto}}" style="height: 600px;" alt="">
  </div>
</div>
    
asked by anonymous 02.11.2016 / 07:27

1 answer

1

Here's what happened:

I was doing everything, but everything was wrong! I was calling the main.php file via http.get ().

What I did: 1 - I made as indicated the .php files for .html, leaving only the files that would return the json as .php 2 - instead of using $ http.get (), I started using ngRoute and ngView. 3 - I made the correct corrections in the Controller through such changes.

Okay, everything went fine, working as it pleased. Thanks guys for the effort, you guys once again helped me!

    
05.11.2016 / 07:18