3

I have an ng-click in my navbar to change the boolean and show my div. When I click it, the boolean changes, but the ng-show doesnt respond.

This html is in my layout file while the controller I'm working with is in my body html file. when i put the above html in my body html file the whole thing works fine? What could be going on? I get no errors from angular or anywhere else. All my script includes are in my layout file as well as my angular app definition.

Html from navbar in layout file:

<div class="navbar-collapse collapse" ng-controller="MoviesCtrl">
    <ul class="nav navbar-nav">
        <li class="active"><a href="index.html"><i class="icon-home icon-white"></i> Today</a></li>
        <li ng-click="flipTwoDay()"><a><i class="icon-folder-open icon-white"></i> Two Days</a></li>
        <li><a href="manager.html"><i class="icon-folder-open icon-white"></i> All</a></li>
     </ul>
 </div>

Html in body file:

<div ng-show="twoDay.show">
    <h1>{{tomorrow}}</h1>
    <div ng-repeat="theat in data.Locations">
        <div class="col-sm-6 col-lg-6">
            <div class="dash-unit">
                <dtitle>{{theat.Name}}</dtitle>
                <hr>
                <div ng-repeat="film in theat.Dates[tomorrow]">
                    {{film.title}}{{film.times}}
                </div>
            </div>
        </div>
    </div>
</div>

JavaScript which lives at the bottom of body cshtml file.

mabuse.page.moviesCtrl = function ($scope, $firebase) {
    var ref = new Firebase("https://mabuse.firebaseio.com/");
    // create an AngularFire reference to the data
    var sync = $firebase(ref);
    $scope.data = sync.$asObject();
    var currentDate = new Date()
    var day = currentDate.getDate()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()
    if (day < 10) {
        dat = '0' + day
    }
    if (month < 10) {
        month = '0' + month
    }
    $scope.today = day + " " + month + " " + year;
    day += 1;
    $scope.tomorrow = day + " " + month + " " + year;
    $scope.twoDay = {show : false};
    $scope.flipTwoDay = function () {
    $scope.twoDay.show = true;
    // $scope.$digest();
    console.log($scope.twoDay.show);
};
console.log($scope.tomorrow);
};
Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
alankalter
  • 31
  • 4
  • code is looking fine. Anyway try ng-if in place of ng-show. and also just for testing change: $scope.twoDay = {show : false}; to: $scope.twoDay.show =false; and, $scope.twoDay = {}; – Ved Jan 22 '15 at 18:52
  • does data.Location ng-repeat shows data? By looking at your code seems like `twoDay.show` variable doesn't belong in scope of `MoviesCtrl` (which belongs to navbar.) – Pankaj Parkar Jan 22 '15 at 18:54
  • 1
    @pankajparkar I am also thinking the same. and one thing more that i found is he is declaring ng-controller="MoviesCtrl" inside div and he is closing it. so ng-controller="MoviesCtrl" is only available for that div portion. not for all body.. – Ved Jan 22 '15 at 18:58
  • @Ved and other thing why `MoviesCtrl` defined as `mabuse.page.moviesCtrl` does that typo? – Pankaj Parkar Jan 22 '15 at 19:00
  • @pankajparkar lets see.. what he replies... – Ved Jan 22 '15 at 19:05
  • hey, so it works now when I wrap the whole body in the layout file with a
    . Before I had two separate controller directives for separate parts. I guess that was the problem? Anyway, thanks alot.
    – alankalter Jan 23 '15 at 00:02

0 Answers0