mercredi 20 avril 2016

Can we write IF statement without else in javascript

I wrote some code to create an simple todo app in angular js. I have the following function code to remove the tasks from the list.

Javascript code

$scope.deleteTask =  function(){
    $scope.tasks.splice(this.$index, 1);
    if($scope.tasks.length < 1){
        $scope.noTask = true;
    }     
};

HTML code

    <li ng-repeat="task in tasks track by $index">  <button ng- click="deleteTask()">x</button></li> </li>
    <p ng-show="noTask">No Tasks Available </p>

I wanted to show a message when there are no tasks in the list. i have achieved this using "if" statement. but i don't need an else here. i am not sure whether its the right way. what will be the proper way to achieve this

Aucun commentaire:

Enregistrer un commentaire