Angular - How to pull a request from another page

0

I was studying angular and wanted to pull the information off the main page, but I'm not able to pull the javascript out.

page repeticao.html:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><body><divclass="container" ng-app="myApp" ng-controller="customersCtrl">
    <div class="row">
        <div class="table-responsive">
            <table class="table table-hover">
                <tbody id="myTable">
                    <tr ng-repeat="x in names | filter:test">
                        <td>{{ x }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("teste.js")
    .then(function (response) {$scope.names = response.data.records;});
});
</script>

</body>
</html>

teste.js (to pull this information and play on the main page):

angular.module('myApp', []).controller('namesCtrl', function($scope) {
        $scope.names = [
            'Jani',
            'Carl',
            'Margareth',
            'Hege',
            'Joe',
            'Gustav',
            'Birgit',
            'Mary',
            'Kai'
        ];
    });
    
asked by anonymous 20.10.2017 / 18:55

1 answer

0

As far as I know, you can not make a call HTTP to a file .js local (correct me if I'm wrong)

You can use this site: MYJSON to host a file in object structure. It will generate a URL to simulate your HTTP call

I made a sample PLUNKER .

If you want to do this locally with a .json , the process is different. I advise you to use the actual HTTP call because you can do the error handlings =)

    
20.10.2017 / 19:08