0

angularJS code:

appModule.controller('dcrlistingCtrl',
    ['$scope', '$modal', '$state', '$rootScope', 'loginService', 'servicePOST', 'appConstants', 'sessionService', '$http',
    function ($scope, $modal, $state, $rootScope, loginService, servicePOST, appConstants, sessionService, $http) {
        alert("trial");

        $scope.contact = "Doctors";
        $scope.contacts =
                [
                    { "patch": "BARIJPUR", "contact": ["RAMA SENA", "SMRITI IRANI", "JAGDISH NAIR"] },
                    { "patch": "Anna", "contact": ["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"] },
                    { "patch": "Peter", "contact": ["RATAN PANDEY", "RAMAN SHIVOLKAR"] }
                ];


        $scope.doctors = function () {
            $scope.contact = "Doctors";

            $scope.contacts = [];

            $scope.contacts =
                    [
                        { "patch": "BARIJPUR", "contact": ["RAMA SENA", "SMRITI IRANI", "JAGDISH NAIR"] },
                        { "patch": "RATANGHAR", "contact": ["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"] },
                        { "patch": "BHIRJ", "contact": ["RATAN PANDEY", "RAMAN SHIVOLKAR"] }
                    ];

        };

        $scope.pharmacists = function () {
            $scope.contact = "pharmacists";

            $scope.contacts = [];

            $scope.contacts =
            [
                { "patch": "DRAMAPUR", "contact": ["RYAN DCOSTA", "SIDDESH NAIK", "ARVIND CHARI"] },
                { "patch": "MAHALSA", "contact": ["TANVI REDKAR", "PRIYANKA BANDODKAR", "GIRISH MATARBHOG"] }
            ];
        };

        $scope.stockists = function () {
            $scope.contact = "stockists";

            $scope.contacts = [];

            $scope.contacts =
                    [
                        { "patch": "SRIJAN", "contact": ["SHILPA NAIK", "ARBAAZ SHAIK", "NAZEEF SHAIK"] },
                        { "patch": "KHANCHAR", "contact": ["AVESH NAIK", "MELROY FERNANDES", "BRIAN DIAS"] },
                        { "patch": "TRINSAL", "contact": ["MEENAKSHI TIWARI", "GAURAV TIWARI"] }
                    ];

        };

    }
])

html code:

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">


            <button type="button" type="button" class="navbar-toggle collapsed" style="float:right;" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="glyphicon glyphicon-option-vertical" style="float:right;"></span>
            </button>


            <button type="button" class="navbar-toggle collapsed" style="float:left;" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <div class="text-center visible-xs">
                <span> <b> Field Work </b> </span>
            </div>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
            <span> <b>Field Work</b> </span>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>


<div class="container-fluid">
    <div class="row">
        <div class="col-sm-2 hidden-xs">

            <ul class="list-group text-center" style="cursor:pointer;">
                <li class="list-group-item" id="heading" style="cursor:default;">{{contact}}</li>
                <div ng-repeat="con in contacts">
                    <li class="list-group-item" id="patch" data-toggle="collapse" data-target='#Dright{{$index}}'>{{con.patch}}<span class="badge">5</span></li>
                    <div class="text-center collapse" id='Dright{{$index}}'>
                    <div class="cell" ng-repeat="cell in con.contact">
                    <li class="list-group-item">{{cell}}</li>
                    </div>
                    </div>
                </div>
            </ul>


        </div>

        <div class="col-sm-7">

            <div class="col-sm-12">
                <button type="button" class="btn btn-primary " ng-click="doctors()"><b>Doctor</b></button>
                <button type="button" class="btn btn-primary " ng-click="pharmacists()"><b>Pharmacist</b></button>
                <button type="button" class="btn btn-primary " ng-click="stockists()"><b>Stockist</b></button>

            </div>



            <div class="col-sm-12">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>Email</th>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>Email</th>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>Email</th>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>Email</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="success">
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                            <td>john@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                        </tr>
                        <tr class="danger">
                            <td>Mary</td>
                            <td>Moe</td>
                            <td>mary@example.com</td>
                            <td>Mary</td>
                            <td>Moe</td>
                            <td>mary@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                            <td>john@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                        </tr>
                        <tr class="info">
                            <td>July</td>
                            <td>Dooley</td>
                            <td>july@example.com</td>
                            <td>July</td>
                            <td>Dooley</td>
                            <td>july@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                            <td>john@example.com</td>
                            <td>John</td>
                            <td>Doe</td>
                            <td>john@example.com</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

any angularJS expert here? help required!

onclick of each button,i am trying to fill the array with new values! but it seems to not happen! am i doing something wrong?

i tried to declare thhe array again in each of the functions so that the old values get flushed out!

any help or advice and changes are appreciated!

here is the result: result

Shri
  • 834
  • 1
  • 12
  • 36
Clyde Dias
  • 195
  • 1
  • 5
  • 18
  • What do you get as a result? I understand that it's not working, but what exactly does that look like? And is that the complete code - how are you tying the html to the js? I don't see a controller declared anywhere. – Andrew Cavanagh Feb 24 '16 at 16:51
  • Did you add angular,module at the top can you please share the exact JS file code – Hassan Tariq Feb 24 '16 at 16:57
  • As a side note `div` cannot be a direct child of `ul`, only `li` can be. [reference](http://stackoverflow.com/questions/11755628/can-i-use-div-as-a-direct-child-of-ul) – ste2425 Feb 24 '16 at 17:08
  • ive just edited and put the full html and controller code! directly cpy pasted the whole code! – Clyde Dias Feb 24 '16 at 17:14
  • Where have you defined your module? – Sachin Kariyattin Feb 24 '16 at 17:27
  • don't worry about the definition of module! its all done! angularJS works perfectly! its only when i define the arrays in each of the functions again, thats when the problem occurs! it does not show! if i remove the array definitions from all of the functions, the list appears fine! but not when the array is defined in the functions! i must be doing something wrong! please note: its the same array that i am populating in each of the button functions! – Clyde Dias Feb 24 '16 at 17:35
  • i just don't know what just happened! it just worked! i cleared the cache of the browser and opened it in a new tab! – Clyde Dias Feb 24 '16 at 17:39
  • thanks guys for attempting! – Clyde Dias Feb 24 '16 at 17:39

1 Answers1

-1

Here's a working plunker of your codehttps://plnkr.co/edit/XZ5Fff?p=preview Seems to work are you seeing any error in your console, Also you don't need to re-declare your $scope.contacts to an empty array.

schutzer
  • 1
  • 1