Love Calculator app using angularjs

Hi, Guys welcome back to my another angular.js application tutorial. We will call this app as Love CalC. This app will take your name and your partner name as input and it will show you how much you are compatible with each other. This App is just for fun.



Ok now I did this app. actually, I want to show you how to work with open apis in angular. When I googled for open API’s I end up with It’s simply amazing there you can find number free API’s.
Let’s see the code.
Besides angular we are going to use.
We will use above two to show the graph.

Let’s see the code.


<!DOCTYPE html>  
<html lang="en" data-ng-app="LoveCalc">  
    <meta charset="UTF-8"> 
    <title>Fun with Love calculater - techumber
    <link rel="stylesheet" type="text/css" href="//"> 
    <div class="ui page grid"> 
      <div class="column" data-ng-controller="LoveCalcCtrl"> 
        <h1 class="ui header aligned center">NG Love Calc
    <script src="//">
    <script src="//">
    <script src="//">
    <script src="//">
    <script src="app.js">

same old HTML code. added all our third party libraries.


<div class="ui segment" data-ng-class="{loading:isProcessing}">  
  <div class="ui two column middle aligned relaxed fitted stackable grid"> 
    <div class="column"> 
      <form class="ui form" data-ng-submit="getResult(data)" name="loveForm"> 
        <div class="field required" data-ng-class="{error: (loveForm.fname.$invalid && loveForm.fname.$dirty)}"> 
          <label>First Name
          <div class="ui left icon input"> 
            <input type="text" 
                   placeholder="First Name" 
            <i class="user icon">
          <div ng-messages="loveForm.fname.$error"> 
            <div data-ng-include="'messages.tpl.html'">
        <div class="field required" data-ng-class="{error: (loveForm.sname.$invalid && loveForm.sname.$dirty)}"> 
          <label>Partner Name
          <div class="ui left icon input"> 
            <input type="text" 
                   placeholder="Second Name" 
            <i class="user icon">
          <div ng-messages="loveForm.sname.$error"> 
            <div data-ng-include="'messages.tpl.html'">
        <button type="submit" class="ui blue submit button" data-ng-disabled="loveForm.$invalid">Get Result
    <div class="ui vertical divider"> 
    <div class="column aligned center" style="height:200px;margin-top: -25px;" data-ng-show="gauge_data[0].label" > 
      <pie-chart data='gauge_data' options='gauge_options'>

HTML form with semantic UI. and added 'pie-chart' directive. When we get the data from the server we this will get the update.


<div class="ui red pointing prompt label transition visible" ng-message="required">This filed is required </div>  

Your message template to show angular forms error messages.


angular.module('LoveCalc', ['ngMessages', 'n3-pie-chart']).  
controller('LoveCalcCtrl', ['$scope', '$http', function($scope, $http) {  
    $scope.gauge_data = [{
        label: "",
        value: 0,
        suffix: "%",
        color: "steelblue"
    $scope.gauge_options = {
        thickness: 5,
        mode: "gauge",
        total: 100
    $scope.getResult = function(data) {
        $scope.isProcessing = true;
        $http.get('process.php?fname=' + data.fname.replace(/ /g, '') + '&sname=' + data.sname.replace(/ /g, ''))
            .then(function(res) {
                $scope.isProcessing = false;
                $scope.gauge_data[0].value =;
                $scope.gauge_data[0].label =;

Hear we creating our module. We are going to get data from our process.php. We will update our scope variables.



$fname = isset($_REQUEST['fname'])?$_REQUEST['fname']:diex('First Person Name Required'); 
$sname = isset($_REQUEST['sname'])?$_REQUEST['sname']:diex('Secons Person Name Required'); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,''.$fname.'&sname='.$sname);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
$headers = array(); 
$headers[] = 'X-Mashape-Key: HERE YOUR MASHAPLE KEY GOES.....'; 
$headers[] = 'Accept: application/json'; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
$server_output = curl_exec ($ch); 
curl_close ($ch);  
print $server_output ; 

function diex($err){  
echo json_encode(array(  
'err'=> $err  

Now, this is important we are using php_curl to interact with mashape API. Don’t forget to add your Mashape key in this code.

Get posts by email

Like what you're reading? Get these posts delivered to your inbox.