10

リンクをクリックした後に html テンプレートを変更しようとしています。値はブール値、初期値は true で適切なテンプレートが読み込まれますが、値が false に変更されると新しいテンプレートが読み込まれず、理由がわかりません。ブール値の初期値が true の場合、他のテンプレートは正常にロードされますが、呼び出されたメソッドではロードされません。助けてください。これが私のコードです:

タスク Ctrl

app.controller('TasksCtrl', ['$scope', 'TaskService', function ($scope, TaskService) {
    // initialize function
    var that = this;
    that.newTask = true;
    that.name = "My name is Nedim";

    that.templates = {
        new: "views/task/addTask.html",
        view: "views/task/viewTask.html"
    };

    // load all available tasks
    TaskService.loadAllTasks().then(function (data) {
        that.items = data.tasks;
    });

    $scope.$on('newTaskAdded', function(event, data){
        that.items.concat(data.data);
    });

    that.changeTaskView = function(){
        that.newTask = false;
        console.log("New task value: " + that.newTask);
    };

    return $scope.TasksCtrl = this;

}]);

task.html

<!-- Directive showing list of available tasks -->
<div class="container-fluid">
<div class="row">
    <div class="col-sm-6">
        <entity-task-list items="taskCtrl.items" openItem="taskCtrl.changeTaskView()"></entity-task-list>  
    </div>
    <div class="col-sm-6" ng-controller="TaskDetailCtrl as taskDetailCtrl">
        <!-- form for adding new task -->
        <div ng-if="taskCtrl.newTask" ng-include="taskCtrl.templates.new"></div>
        <!-- container for displaying existing tasks -->
        <div ng-if="!taskCtrl.newTask" ng-include="taskCtrl.templates.view"></div>

    </div>
</div>

entityList ディレクティブ

app.directive('entityTaskList', function () {
return {
    restrict: 'E',
    templateUrl: 'views/task/taskList.html',
    scope: {
        items: '='
    },
    bindToController: true,
    controller: 'TasksCtrl as taskCtrl',
    link: function (scope, element, attrs) {
    }
};

});

ディレクティブ テンプレート

<ul class="list-group">
<li ng-repeat="item in taskCtrl.items" class="list-group-item">
    <a ng-click="taskCtrl.changeTaskView()">
        <span class="glyphicon glyphicon-list-alt" aria-hidden="true"> </span> 
        <span>{{item.name}}</span>
        <span class="task-description">{{item.description}}</span>
    </a>
</li>

{{taskCtrl.newTask}}

4

1 に答える 1