ionic restful authentication to POST and get data from php

im working on an ionic project to create android and ios app. im new in ionic and need help to understand how to make a login trough restful services hosted on my server.

the restful uses this auth for every POST or PUT request:

username: admin
pass: 123123

so i am testing a POST request. i have no idea how to authenticate. the serverside is set up and running. and the api had been tested and no bug. (tested using cocoa restclient)

ok. this is my app.js

angular.module('tapp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider){
  $stateProvider
   .state('testapp', {
     url: "/tapp",
     abstract: true,
     templateUrl: "template/menu.html",
     controller: 'MenuCtrl'
})
.state('tapp.home', {
      url: '/home',
      views: {
          'tappMenu': {
              templateUrl: 'template/home.html',
              controller: 'HomeCtrl'
          }
      }
})
.state('tapp.dash', {
      url: '/dash',
      views: {
          'tappMenu': {
              templateUrl: 'template/dash.html',
              controller: 'DashCtrl'
          }
      }
})

$urlRouterProvider.otherwise('/tapp/home');

here is my controller:

.controller('HomeCtrl', function($scope, $http){
    $scope.formData = [] // just testing post data
    $scope.submit = function(){
      var data = $scope.formData.push($scope.inputData);
      $http.post('http://localhost/tapp-server/posted', data);
   };
}

my php function (using codeigniter rest server)

public function posted_post()
{
    $this->response(json_encode($_POST), 200);
}

the issue here is, i dont know how to apply the basic restful authentication whenever the app will post the data to the php because whenever it post the data, i get error as "not authorized".

for other data such as getting the data using GET, i receive the data and processed flawlessly. only on this POST part i am in confusion.

Check this http://vitalflux.com/angularjs-post-data-using-ajax-spring-mvc-example/, it might help you to send post message instead of options. Otherwise, attach the response you get from the server so we can help you more

yes. i got it. $http is a low level request. for high level request i can use $resource.

found something in angular docs.

https://docs.angularjs.org/api/ngResource/service/$resource

can use this too:

https://github.com/mgonto/restangular#table-of-contents