LukaszWatroba / v-accordion

Multi-level accordion component for AngularJS.
http://lukaszwatroba.github.io/v-accordion
MIT License
310 stars 100 forks source link

Variables go undefined when inside the <v-> tags #82

Open chetanku opened 7 years ago

chetanku commented 7 years ago

Hey,

I have an issue where the $scope variables are undefined when inside the tags.

For example html :

<html ng-app="myapp">
<head>
    <link href="bower_components/v-accordion/dist/v-accordion.css" rel="stylesheet" />
      <link href="bower_components/angular-material/angular-material.css" rel="stylesheet" />
    </head>
    <body ng-controller="ctrl">
        <v-accordion class="vAccordion--default" multiple>

  <!-- add expanded attribute to open the section -->
  <v-pane expanded>
    <v-pane-header>
    header 1
    </v-pane-header>

    <v-pane-content>
      <md-input-container>
        <label>New</label>
          <input ng-model="description">
        </md-input-container>
        <md-button ng-click="button()">Name</md-button>
    </v-pane-content>
  </v-pane>

</v-accordion>

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script type="text/javascript" src="bower_components/angular-material/angular-material.js"></script>
<script src="bower_components/angular-aria/angular-aria.min.js"></script>
<script src="bower_components/v-accordion/dist/v-accordion.js"></script>
        <script src="app.js"></script>
    </body>
</html>

AngularJS:

var app = angular.module('myapp', ['ngMaterial','ngAnimate','vAccordion']);
app.controller('reminderCtrl', function($scope) {

    $scope.button =function(){
console.log($scope.description);
};
});

OUTPUT: Console: undefined

Any help will be great.

caribnow commented 7 years ago

Same problem here. Did you solve for this issue?

caribnow commented 7 years ago

Found a solution. ng-model="$parent.$parent.scopeVariable". Add the $parent.$parent. to get back into the controller scope.

chetanku commented 7 years ago

Hey ,

This is what my code looks like. If I remember it right, I initialized the controller in the md-content below, instead of the body and it worked. Please let me know if it works.

header 1 Name