Thursday 25 February 2016

Nested ng-repeat

 
 
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Angularjs/angular.js"></script>
    <script src="Script/AngularjsBinding.js"></script>
</head>
<body>
    <div ng-app="myApp" ng-controller="myController">
        <ul>
            <li ng-repeat="country in countries">
                {{country.name}}
                <ul>
                    <li ng-repeat="city in country.cities">
                        {{city.name}}
                        <ul>
                            <li ng-repeat="street in city.Area">
                                {{street.name}}
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</body>
</html>
JS
/// <reference path="../Angularjs/angular.js" />
var app = angular.module("myApp", [])
                 .controller("myController", function ($scope) {
                     var countries = [
                         {
                             name: "India", cities: [
                                {
                                    name: "Mumbai", Area: [
                                        { name: "Tunga" },
                                        { name: "Saki naka" },
                                        { name: "Powai" },
                                        { name: "Hiranandani" },
                                    ]
                                },
                                { name: "Chennai" },
                                { name: "UP" }
                             ]
                         },
                         {
                             name: "Australia", cities: [
                                { name: "Melbourne" },
                                { name: "Perth" },
                                { name: "Canberra" },
                                { name: "Sydney" }
                             ]
                         },
                         {
                             name: "England", cities: [
                                { name: "London" },
                                { name: "Menchester" },
                                { name: "Bristol" },
                                { name: "Birmingham" }
                             ]
                         },
                     ];
                     $scope.countries = countries;
                 });
 

Angularjs Events

 
 
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Angularjs/angular.js"></script>
    <script src="Script/AngularjsEvents.js"></script>   
</head>
<body ng-app="myApp" ng-controller="myController">
    <table border="1" cellpadding="6px" cellspacing="0">
        <thead>
            <tr>
                <th>
                    Languages
                </th>
                <th>
                    Likes
                </th>
                <th>
                    DisLikes
                </th>
                <th>
                    Likes/Dislikes
                </th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="language in languages">
                <td>
                    {{language.name}}
                </td>
                <td align="center">
                    {{language.Likes}}
                </td>
                <td align="center">
                    {{language.Dislikes}}
                </td>
                <td>
                    <input type="button" value="Likes" ng-click="incrementLikes(language)" />
                    <input type="button" value="Dislikes" ng-click="incrementDisLikes(language)" />
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>
JS
/// <reference path="../Angularjs/angular.js" />
var app = angular.module("myApp",[])
                 .controller("myController", function ($scope) {
                     var languages = [
                         { name: "Asp.net", "Likes": 0, "Dislikes": 0 },
                         { name: "MVC", "Likes": 0, "Dislikes": 0 },
                         { name: "C#", "Likes": 0, "Dislikes": 0 },
                         { name: "Angularjs", "Likes": 0, "Dislikes": 0 },
                         { name: "Javascript", "Likes": 0, "Dislikes": 0 },
                         { name: "Jquery", "Likes": 0, "Dislikes": 0 },
                     ];
                     $scope.languages = languages;
                     $scope.incrementLikes = function (language) {
                         language.Likes++;
                     }
                     $scope.incrementDisLikes = function (language) {
                         language.Dislikes++;
                     }
                 })