0

ng-clickで変数を true に設定していますが、その下の div が表示されません。この投稿をフォローしましたが、おそらくng-repeatでは機能しないようです? これがプランカーです: http://plnkr.co/edit/90G1KAx9Fmf2SgRs5gYK?p=preview

angular.module('myAppApp', [])

    .controller('MainCtrl', function ($scope) {
        $scope.notes = [{
            id: 1,
            label: 'First Note',
            done: false,
            someRandom: 31431
        }, {
            id: 2,
            label: 'Second Note',
            done: false
        }, {
            id: 3,
            label: 'Finished Third Note',
            done: true
        }];



        $scope.reach= function (id) {
            //the assignment below works
            //$scope.flag = true;
            alert("hello there");
        };


});



<div ng-app="myAppApp">
    <div ng-controller="MainCtrl">
      <div ng-repeat="note in notes">
        {{note.id}} - {{note.label}} -
        <a href="#" ng-click="flag = true;reach(111);">click me</a>

      </div>

      <div class="row" id="" ng-show="flag">I'm Here</div>
    </div>
  </div>
4

2 に答える 2

0

使用することをお勧めしますng-init

<div ng-repeat="note in notes" ng-init="parent=$parent">

それとその後

<a href="#" ng-click="parent.flag = true;reach(111);">click me</a>

以下のデモをご覧ください

angular.module('myAppApp', [])

.controller('MainCtrl', function($scope) {
  $scope.notes = [{
    id: 1,
    label: 'First Note',
    done: false,
    someRandom: 31431
  }, {
    id: 2,
    label: 'Second Note',
    done: false
  }, {
    id: 3,
    label: 'Finished Third Note',
    done: true
  }];



  $scope.reach = function(id) {
    //$scope.flag = true;
    alert("hello there");
  };


});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body>
  <div ng-app="myAppApp">
    <div ng-controller="MainCtrl">
      <div ng-repeat="note in notes" ng-init="parent=$parent">
        {{note.id}} - {{note.label}} -
        <a href="#" ng-click="parent.flag = true;reach(111);">click me</a>

      </div>

      <div class="row" id="" ng-show="flag">I'm Here</div>
    </div>
  </div>
</body>

于 2015-04-01T16:21:41.783 に答える