Manage Simple State in an AngularJS Controller

Lukas Ruebbelke
InstructorLukas Ruebbelke

Share this video with your friends

Send Tweet

We are going to learn how to manage simple states within our controller. We are going to learn how to toggle between the editing and creating bookmark states and how to sequence those interactions in the controller.

note: The code for this lesson can be found on Github. The tags correspond to the lessons.

Nate
Nate
~ 6 years ago

I'm wondering why you are declaring functions and then attaching them to the scope. Can't this be accomplishing in one step?

For example, you have the following:

function startCreating() { $scope.isCreating = true; } $scope.startCreating = startCreating;

Can this be written as follows?

$scope.startCreating = function () { $scope.isCreating = true; }

Carlo
Carlo
~ 5 years ago

Couldn't we achieve the same result with just two functions?

function setCurrentAction(action) {
	$scope.currentAction = 'action';
}

function cancelCurrentAction() {
	$scope.currentAction = null;
}

Doing so we could also re-use quickly implement additional actions.

Achim Hendriks
Achim Hendriks
~ 4 years ago

~Minute 6:15 "it's actually a property": Why are you emphasizing using ng-if="xxx" with no brackets here and using ng-if="xxx()" (with brackets) every where else?