Я использую директиву дважды на одной странице. Внутри директивы я поместил кнопку, которая при нажатии удаляет первую директиву и показывает другую. Но значения вообще не меняются, даже когда срабатывает функция ng-click. Что я делаю не так? Вот мой HTML-код.
<body ng-controller="mainCtrl">
<new-directive ng-show="firstDirective" passvar="first passing value"></new-directive>
<new-directive ng-show="secondDirective" passvar="second passing value"></new-directive>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
Файл test.html:
{{content}}, {{passvar}} <button ng-click="otherOne()">show other directive</button>
JS-файл:
app.controller('mainCtrl', function($scope){
$scope.firstDirective = true;
});
app.directive('newDirective',function(){
// Runs during compile
return {
restrict: 'E',
templateUrl: 'test.html',
scope: {
passvar: '@'
},
controller: function ($scope) {
$scope.content= 'Random Content';
$scope.firstDirective = true;
$scope.firstDirective = false;
$scope.otherOne = function(){
$scope.firstDirective = false;
$scope.secondDirective = true;
}
}
};
});
Даже для отображения первой директивы мне нужно добавить $scope.firstDirective = true; в основном контроллере, а не в контроллере директивы.