Angular Service Example

The following code demonstrates how a service can be created in AngularJS.

index.html

<html>
 <head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.min.js"></script>
 <script src="app.js"></script>
 <script src="anotherModule.js"></script>
 </head>
 <body>
 <div ng-app="mainModule" ng-controller="mainController as alias">
 <b>Invoice:</b>
 <p>The input is: {{alias.quantity}}</p>
 <div>
 Quantity: <input type="number" min="0" ng-model="alias.quantity"required>
 </div>
 <div><p>Add 4 and double it!</p></div>
 <div>
 <b>Result:</b>
 <span>{{alias.total(alias.quantity)}}</span>
 <button class="btn" ng-click="alias.paid(alias.total(alias.quantity))">Pay</button>
 </div>
 </div>
 </body>
</html>

app.js

angular.module('mainModule', ['dependencyModule'])
.controller('mainController', ['theService', function(theService) {

  this.quantity = 1;

  this.total = function total(number) {
    return theService.inService(number + 4);
  };

  this.paid = function pay(parameter) {
    window.alert(parameter);
  };

}]);

anotherModule.js

angular.module('dependencyModule', [])
  //currencyConverter is the service
.factory('theService', function() {

  var functionInService = function (parameter2) {
    return parameter2 * 2;
  };

  return {
    inService: functionInService
  };
});

Services can be used to share code across controllers.

Install Mongodb on Fedora 23

To install Mongodb on Fedora 23 go to

https://www.mongodb.org/downloads

On the Linux tab go to version RHEL 7 Linux 64-bitmongodbSreenshot

$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.3.tgz

Untar the tarball

$ tar -zxvf mongodb-linux-x86_64-rhel70-3.2.3.tgz
$ echo $PATH
$ sudo ln -s ~/Downloads/mongodb-linux-x86_64-rhel70-3.2.3/bin/mongo /usr/local/bin/mongod
$ mongod --version
MongoDB shell version: 3.2.3
$ mongo --version
MongoDB shell version: 3.0.8

Make the directory /data/db

$ mkdir -p /data/db/

Change the permissions on both /data and /data/db

$ sudo chmod 777 /data
$ sudo chmod 777 /data/db

Make sure you are in the mongo directory in /Downloads, ~/Downloads/mongodb-linux-x86_64-rhel70-3.2.3/bin/mongo . Next copy all here to /usr/local/bin/

$ cp * /usr/local/bin

From anywhere run the server with

$ mongod

At the end of the output you should get

 ....... waiting for connections on port 27017

In your browser navigate to localhost:27017
Selection_005
I found that on Fedora both mongod and mongo start the server. mongo should start the Mongodb shell only.

$ mongo

Should run the mongo shell, however on fedora you will need to use,

 $ sudo mongod

And this only works when the Mongodb server is already running.
Continue to Basics of MongoDB Shell