Question

Why I can't change value using function? AngularJS

html:

<div ng-controler='TestCtrl' id='TestCtrl'>
    <h1>Test: {{test.name}}</h1>

    <div ng-hide='showTest'>
        <div class='content'>
            <p>First name: <input ng-model='firstName'></p>
            <p>Last name: <input ng-model='lastName'></p>
        </div>
        <div jq-ui-button ng-click='doSth()'>
            Do something
        </div>
    </div>
</div>

JS:

app.controller('TestCtrl', function ($scope) {
    $scope.showTest = false;
    $scope.test = {name:'Test name'};

    $scope.doSth = function() {
        $scope.showTest = true;
    }
}

It does not work. But when I write:

<div jq-ui-button ng-click='showTest = true'>

It works.

Where is the problem?

Était-ce utile?

La solution

You must write ng-controller not ng-controler. That's why your code is not used. First line in your HTML.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top