chat

Byadmin

Jul 21, 2016

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>

        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">

        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

        <!-- ionic/angularjs js -->
        <script src="lib/ionic/js/ionic.bundle.js"></script>

        <!-- cordova script (this will be a 404 during development) -->
        <script src="cordova.js"></script>

        <!-- your app's js -->
        <script src="js/app.js"></script>
    </head>
    <body ng-app="starter">

        <ion-pane ng-controller="ChatCtrl">


            <ion-header-bar class="bar-stable">

                <h1 class="title">Chat App :)</h1>

            </ion-header-bar>
            <ion-content class="has-footer">
              <div class="list list-inset">
            <label class="item item-input">
            <i class="icon ion-search placeholder-icon"></i>
            <input type="text" placeholder="Search" ng-model="SearchInput">
            </label>
            </div>
                <div class="list">

                    <a ng-repeat="c in chatLogs | filter : SearchInput" class="item item-icon-left" href="#">
                        <i class="icon {{c.chat_icon}}"></i>
                        <h2>{{c.chat_message}}</h2>
                        <em>{{c.username}}
                            on
                            {{c.chat_date}}</em>
                    </a>

                </div>

            </ion-content>

            <ion-footer-bar class="item-input-inset footer-item-input-insert bar-dark">
                <label class="item-input-wrapper">
                    <input type="text" placeholder="Message" ng-model="newMsg">
                </label>
                <button ng-click="postMsg(newMsg)" class="button button-clear" >
                    Reply
                </button>
            </ion-footer-bar>
        </ion-pane>

    </body>
</html>

app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

            // Don't remove this line unless you know what you are doing. It stops the viewport
            // from snapping when text inputs are focused. Ionic handles this internally for
            // a much nicer keyboard experience.
            cordova.plugins.Keyboard.disableScroll(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
})

.controller('ChatCtrl', function($scope, $http, $ionicPopup) {

    var icon = 'ion-printer';
    var name = 'Tee';

    var reload = function() {
        $http({
            url: 'http://203.158.144.140/demo_ionic_chat/Home/GetChat'
        }).then(function(res) {
            $scope.chatLogs = res.data;
        });
    }
    $scope.postMsg = function(newMsg) {
        $http.post(
            'http://203.158.144.140/demo_ionic_chat/Home/PostChat',
            {
                'username': name,
                'chat_message': newMsg,
                'chat_icon': icon
            },
            {
                method: 'POST',
                headers: {'Content-Type':'application/x-www-form-urlencoded;charset=utf-8;'}
            }
        ).then(function(res) {
            //console.log(res);
            $scope.newMsg='';
            reload();
        });
    }

    //init function;
    reload();


})

 

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.