How to write basic authentication in AngularJS to show JSON data coming from API in table?
<p>I have one rest API which has basic authentication with user-id and password (123:123), while I'm running code showing unauthorized in js console. how to add basic authentication in function so that it can be authorized like this code</p>

<pre><code> headers: {'Authorization': 'Basic ' + btoa("xxx:yyy")},
</code></pre>

<p>my code</p>

<pre><code>   &lt;body&gt;

        &lt;div ng-app="myApp" ng-controller="customersCtrl"&gt;

            &lt;table&gt;
                &lt;tr ng-repeat="x in names"&gt;
                    &lt;td&gt;{{ x.name }}&lt;/td&gt;
                    &lt;td&gt;{{ x.city }}&lt;/td&gt;

                &lt;/tr&gt;
            &lt;/table&gt;

        &lt;/div&gt;

        &lt;script&gt;
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {

        $http.get("https://example.com/name/data/1")

        .then(function (response) {$scope.names = response.data.records;});
    });
        &lt;/script&gt;

    &lt;/body&gt;
</code></pre>