문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top