Postingan lainnya
Data yang diambil dari database tidak tampil di index
//Module Angular var myApp = angular.module ('myApp', ['ngRoute']);
myApp.directive('headerTitle', function() { return{ restirct : 'A', templateUrl : 'header.html' } });
myApp.directive('keduaTitle', function() { return{ restirct : 'A', templateUrl : 'part.html', controller : function($scope, $http) {
/*$scope.data = [{ nama: 'Heriadian', kota: 'Jakarta'}, {nama: 'Afif', kota: 'Bandung'}, {nama: 'Cungs', kota: 'Medan'}]; */
$http.get('koneksi.php').success(function(hasil){ $scope.data = hasil; }); } }; });
//route myApp.config(function($routeProvider){
$routeProvider .when('/tambahinfo',{ templateUrl : 'index2.html', controller : 'add' }) .when('/kontak',{ templateUrl : 'kontak.html' }) .otherwise({redirectTo: '/'});
});
myApp.controller('add', function($scope){
$scope.tambahData = function(){ $scope.data.push({ nama : $scope.namabaru, kota : $scope.kotabaru }); };
});
koneksi.php
<?php header("Access-Control-Allow-Origin: *");
$host = 'localhost'; //127.0.0.1 $user = 'root'; $pass = ''; $db = 'angular';
$link = mysqli_connect($host, $user, $pass, $db) or die(mysqli_error($link));
$query = "SELECT * FROM tb_data"; $result = mysqli_query($link, $query) or die('run query gagal');
$output = "";
while( $row = mysqli_fetch_assoc($result)){ if ($output != ""){ $output .= ","; }
$output .= '{"nama":"'. $row["nama"].'",'; $output .= '"kota":"'. $row["kota"].'"}';
}
$output = '['.$output.']';
echo $output;
?>
1 Jawaban:
ini angularjs ya om? kenapa gak pake Angular aja? sekarang udah versi 5 lho :D