My friends

Deebhana is friends with Srilakshmi Mallavolu

As the $http is the Asynchronous call function control will not wait till the data is returned from the service.
Hence we need to us Deferred and promise objects.

Check this link it will be helpful.
www.tothenew.com/blog/angularjs-deferred...-basic-understanding


Here is the code i have used

<script>
var app = angular.module("mymodule", []);

app.controller("myctrl", function ($scope, comment_service) {

// The data is returned using the promise and deferred , as it is a Asynchronous call

comment_service.getComments().then(function (data) {
$scope.Comments_result = data;
})
});


app.service('comment_service', function ($http, $q) {

this.getComments = function () {

// As this is a asynchronous call we are calling the deferred method
var defered = $q.defer();

$http.get(" jsonplaceholder.typicode.com/comments ").then(function (comments) {

defered.resolve(comments.data);

});
// Before the service data is available we are returning the promise object

return defered.promise;

}
});

</script>

Read More...

Srilakshmi Mallavolu replied to the topic 'How to bind scope variables inside HTML Div s' in the forum. 7 months ago

<script>
var app = angular.module("myModule", []);
app.controller("mycntrl", function($scope) {
$scope.message= "Welcome to hyderabad techies page";
});
</script>


Below is the Code to Bind the scope variables in the HTML
<div ng-app="myModule" ng-controller="mycntrl">
{{message}}
</div>

Read More...

Srilakshmi Mallavolu replied to the topic 'How to create a Module in AngularJS?' in the forum. 7 months ago

Module is the Collection od controllers,sservices etc..

Following is the syntax to create a module

<script>
var app= angular.module("Module_Name",[])
// module contains the controllers
app.controller("Controller_Name", function(){
// Logic
});

</script>

Read More...

The main purpose of Angular service is to share the Common code between deifferent pages.
To create custom angular servicce we can use the below code

var app = angular.module("mymodule", []);

app.controller("myctrl", function ($scope, service_name) // service name should be injected in the controller
{
$scope.Name = service_name.method(); // the service method is called in the controller
}};
app.service('service_name', function() {
this.method= function(){
return "This is a angular service example";

}
});

To Display the Data returned from the Angular service in the User Interface as follows:

<body ng-app="mymodule" ng-controller="myctrl">

{{Name}}

</body>

Read More...

The Following are the steps to talk to a service url

$http.get("https://j.......")
.then(function (result) {

$scope.Getresult= result.data;
})
When ever you use the $http then we should inject it in the controller as below
var app = angular.module("mymodule", []);
app.controller("myctrl", function ($scope, $http)


To display the Data in the User Interface

<div ng-repeat="x in Getresult">
{{x.id}}
{{x.name}}


Read More...

You can use ng-model directive to the element where user is providing input.

For example: <input type="text" ng-model="info" placeholder="search" />


Now we can use this variable info in the controller as below

$scope.info;

Read More...

Following are the steps to talk to a service URL

var app = angular.module("mymodule", []);

app.controller("myctrl", function ($scope, $http) {

$http.get(" jsonplaceholder.typicode.com/comments ")

<!-- calling the service URL-->

.then(function (comments) {

<!-- After calling the service URL then the function should be implemented -- >

$scope.Data = comments.data;
})
});

Displaying The Data on User Interface

<body ng-app="mymodule" ng-controller="myctrl">
<div ng-repeat="x in Data">
{{x.id}}
{{x.name}}

</div>

</body>

Read More...

var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope)
{
$scope.Name="Srialkshmi"; <!-- String Declaration-->
}
app.controller("myctrl2",function($scope)
{
$scope.myarray = [ 'S','R','I']; <!--Array Declaration>
}
app.controller("myctrl3",function($scope)
{
$scope obj=[
{ name:'Johm' city:'Bellevue'},
{name:'Amar' city:'Redmond'}
];
}

Read More...

For iterating the object in UserInterface we use ng-repeat directive.
Here is the example:

<div ng-repeat="x in names">
<b>{{x.name}}</b>
<br>
<I>{{x.City}}</I>
</div>
Assume the script as
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
$scope.names = [
{ name: 'Srilakshmi', City: ' Vijaywada' },
{ name:'Anuradha' ,City:'Gntur}'

];
});
</script>

Read More...

Srilakshmi Mallavolu replied to the topic 'Can someone give 2or 3 examples for filters?' in the forum. 7 months ago

Filters are used to format the data
It can be added by using the Pipe operator
Here are some of the examples for the filters
1. order By
2Lower case
3. Upper case etc..
Here is the sample code :
<html>
<script src=" ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js "></script>
<body ng-app="myApp" ng-controller="namesCtrl">

<div>

<p>Names ordered by country :</p>
<ul>
<li ng-repeat="x in names | orderBy:'country'">
{{ x.name }}
{{ x.country }}
</li>
</ul>

</div>

<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
{name:'Srilakshmi',country:'Vijayawada'},
{name:'Venkatesh',country:'Bhimavaram'},
{name:'Anuradha',country:'Vijayawada'},
{name:'NeelaDevi',country:'Guntur'},
{name:'Ranganath',country:'vijayawada'},

];
});
</script>

</body>
</html>

Read More...

Srilakshmi Mallavolu replied to the topic 'Create a simple application like gmail Inbox?' in the forum. 7 months ago

<html>
<head>
<title>MyfirstangularJS script</title>
<script src=" ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js "></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div>
<H1> INBOX ({{Gmail.length}})</H1> <!--counts the no of objects -->
</div>
<div>
<input type="text" name="search" placeholder="Search" ng-model="search_test" /> <!-- the search is storesd in the search_test variable -->
</div>
<div ng-repeat="x in Gmail | filter:search_test"> <!-- filter is used to format the data -->
<b>{{x.sub}}</b>
<br>
<I>{{x.Desc}}</I>
</div>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
$scope.Gmail = [
{ sub: 'Welcome', Desc: ' Welcome to the first angular js application' },
{ sub: 'Request for the file', Desc: 'I need the documents required for the admission' },
{ sub: 'Sending the file', Desc: 'I Have sent you the file required' },
{ sub: 'Preapring for work', Desc: ' This is a free course for the immigrants in USA' },
{ sub: 'Admission', Desc: 'To the Addmission in the college follow the rules' },
{ sub: 'Displaying the course details', Desc: ' Here is the file for the course' }

];
});
</script>
</body>
</html>

Read More...

Srilakshmi Mallavolu replied to the topic 'How to link your controller to HTML code?' in the forum. 7 months ago

Angular Js uses ng-controller directive to bind with the Html
Example:
<html>
<head>
<script src=" ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js "></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div>
<!--
-->
</body>
</html>

Read More...

Srilakshmi Mallavolu replied to the topic 'How to create a controller in Angular JS?' in the forum. 7 months ago

Controller is used to controls the Angular JS applications.
Controller holds the Logic to be performed. It the collection of functions
Controllers are created in the Module.
Each module can contain any number of controllers.

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope)
{
// Logic
});
app.controller("myctrl2",function($scope)
{
//Logic
});
</script>

Read More...