I am back again with a basic example on AngularJS on how to display the data from a set or array or JSON array, and how to add or insert or append data in an existing JSON array, and at the same time, how could we avoid empty data or duplicate records to get pushed into the JSON array.
This time I am back with Screencast Video tutorials or presentation whatever you call it is, and this is my first screen-cast video presentation too and that too in AngularJS; going forward, I will try to improve my voice and presentation skills, which will help me and you to get some online tutorials going forward.
Since this is my first video, I expect your valuable feedback on where I have to improve myself – which will help me grow further for a better presentation next time. I appreciate your feedback.
Ok – let me come back to this basic AngularJS tutorial; in this tutorial, you can see how to use the ngRepeat directive, forEach global API, and, while inserting data, how to avoid duplicate or empty data to get a push into the JSON array.
Here is the screen-cast video, which explains you well in detail in case you are a starter in AngularJS or about to learn AngularJS:
Demo | Download
JavaScript Code:
var wittyApp = angular.module('wittyApp',[]);
function AvoidDuplicateEntries($scope){
$scope.movies = [
{moviename: 'SuperMan'},
{moviename: 'SpiderMan'},
{moviename: 'BatMan'}
];
var someMovie = $scope.movies;
$scope.addMovie = function (){
var newMovie = $scope.moviename;
var oldmovies;
if(newMovie){ //This will avoid empty data
angular.forEach($scope.movies, function(eachmovie){ //For loop
if(newMovie.toLowerCase() == eachmovie.moviename.toLowerCase()){ // this line will check whether the data is existing or not
oldmovies = true;
}
});
if(!oldmovies){
someMovie.push({moviename:newMovie});
}
}
}
}
HTML Code:
<div style="padding:20px" ng-app="wittyApp" id="ng-app" ng-controller="AvoidDuplicateEntries">
<h1>Basic App using AngularJS</h1>
<table class="table table-bordered" style="width:220px;">
<thead>
<tr><td>#</td>
<td>Movie Name</td></tr>
</thead>
<tr ng-repeat='movie in movies'>
<td>{{$index+1}}</td>
<td>{{movie.moviename}}</td>
</tr>
</table>
<form ng-submit="addMovie();">
<input type="text" ng-model="moviename" size="30" placeholder="Which movie you want to watch" /><br />
<input type="submit" class="btn btn-primary" value="Add Movie">
</form>
</div>
Liked it? Appreciate your feedback about my first video and first example on AngularJS :)
More to come – keep visiting us!
Read more from Programming
- Getting Started with Google Web Starter Kit
- Modifying WordPress to Allow website Authors to choose the Related Posts
- How to display Latest Updated Date and Time in WordPress posts
- Simple Profit or Loss Calculator with AngularJS
- Avoid empty and duplicate records to get pushed in AngularJS
- Toggle or Show or Hide is pretty easy with AngularJS
- New to AngularJS – Here are few basics to learn this framework!
- Backlift can create web apps with automatized back end coding
- CSS Front-end Responsive Frameworks and Grids Compared
