我遇到了一個奇怪的問題。我寫了我自己的指令。我試圖用AngularJs手風琴不能打開,具有is-open屬性
是開
屬性來指定手風琴組需要根據命名$scope.state
模型被打開。不幸的是,它的屬性isOpen總是假的,即使它在checked()
函數中變爲true。
Directive.html
<accordion>
<accordion-group class="my-panel-body" ng-class="{'my-panel-heading-checked':state.isOpen,'my-panel-heading-default':!state.isOpen}" is-open="state.isOpen">
<!--Accordion header -->
<accordion-heading id="{{groupId}}" >
<div ng-click="checked()" >
<i class="pull-left glyphicon" ng-class="status"></i> {{title}}
</div>
</accordion-heading>
<!--Accordion content -->
</accordion-group>
</accordion>
Directive.js
angular.module('locale').
directive('accordionList', function() {
return{
restrict: 'A',
scope: {
title: '=',
result: '=',
groupId: '='
},
templateUrl: 'html/accordionList.html',
controller: function($scope){
var glyphicon = 'glyphicon glyphicon-';
var status = glyphicon + 'unchecked';
$scope.state = {
isOpen: false
}
$scope.status = status;
$scope.checked = function(){
console.log($scope.state.isOpen) //It is always false!
if ($scope.state.isOpen) {
$scope.state.isOpen = false;
$scope.status = status;
}
else { //Always entering this part of code!
console.log("FLAG");
$scope.state.isOpen = true; //True only here when invoked.
$scope.status = glyphicon + 'check';
console.log($scope.state.isOpen);
}
}
}
};
});
我將不勝感激任何幫助。我不知道什麼是不工作。
你可以爲它做一個笨蛋或小提琴嗎? – varit05