The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Building an Angular App: Simple States

Building an Angular App: Simple States

8:44
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](https://github.com/eggheadio/egghead-angularjs-from-scratch-getting-started/tree/04-simple-states). The tags correspond to the lessons.
Watch this lesson now
Avatar
egghead.io

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. note: the tags correspond to the lessons.

Avatar
shawn

OK, this post got duplicated as not sure how orig got under controllers
Further fix for ng 1.3.8 - the code to reset, I needed to explicitly set the member as it was setting an object, thus the comparison is using an object vs. string.

function resetCreateForm() {
            $scope.newBookmark = {
                title: '',
                url: '',
                category: $scope.currentCategory.name
            };
        }
In reply to egghead.io
Avatar
Nate

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;
}

Avatar
Carlo

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?