Angular - Test

by Amitesh Kumar

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
    <div ng-repeat="color in colors">
        <!-- <div>{{color.color}}</div> -->
        <div color-directive></div>
    </div>
    <select name="data_source" class="form-control" ng-model="data.data_source" ng-options="c.name for c in data_sources track by c.id"></select>
    <button onclick ="f(p)">{{data.data_source.id}}--{{data.data_source.name}}</button>

</div>
<script>var p = {a:2}</script>
xxx</button>
<input type="text" required>
    <input type="submit">

JavaScript

debugger;
angular.module("app", [])
.directive('colorDirective', function() {
        return {
            restrict: 'A', 
            template: 'Nameh: {{color.color}}'
        };
    })
    .controller('ctrl', ['$scope',

function ($scope) {
    $scope.model = {
        categories: [{
            "Id": 1,
            name: '1'
        }, {
            "Id": 2,
            name: '2'
        }],
        subCategories: [{
            "parentId": 1,
            name: 'a1'
        }, {
            "parentId": 1,
            name: 'a2'
        },
                       {
            "parentId": 2,
            name: 'a3'
        }]
    }
    $scope.colors = [
        {
            color: "Red" 
        }, 
        {
            color: "Green"
        }
    ];
    $scope.data ={
        data_source:{id:"2",name:"2x"}
        
    }
    $scope.data_sources =[
        {id:"1",name:"1x"},
        {id:"2",name:"2x"},
        {id:"3",name:"3x"},
        
    ]
    $scope.getSubCategories = function(parentId){
        var result = [];
        for(var i = 0 ; i < $scope.model.subCategories.length ; i++){
            if(parentId === $scope.model.subCategories[i].parentId){
                result.push($scope.model.subCategories[i]);               
            }
        }
        console.log(parentId)
        return result;
    }
}])
f = function(p){
 alert(p.a)   
}