Dmitry Dmitry - 5 days ago 6
AngularJS Question

Several (multi) functions of the controller AngularJS

I want to use several functions in one controller. First family makes a request, the second part of the page should display by pressing the button (as here http://www.w3schools.com/angular/tryit.asp?filename=try_ng_events_toggle).
The first function is working fine, but the second is not.

app.controller('DemoCtrl', function($http) {},function($scope){})


This is the second function of the controller:

function($scope){
$scope.showMe=false;
$scope.myFunc=function() {
$scope.showMe=!$scope.showMe;
}


As planned at the touch of a button should show the page:
``

<body ng-app="jsbin">
<div ng-controller="DemoCtrl as vm">
<button ng-click="myFunc()">Click Me!</button>
<div ng-show=vm.showMe>
<h1>Menu:</h1>
<div>Pizza</div>
<div>Pasta</div>
<div>Pesce</div>
</div>
</div>


`
Sourse:http://zalil.su/3296697

Answer

angular controller takes one function with all dependencies. app.controller('DemoCtrl', function($http,$scope) { $scope.showMe=false;

 $scope.myFunc=function() {
 $scope.showMe=!$scope.showMe;
 }

 $scope.makeAjax= function(){
    $http.something()...
 }

})

got through this link https://docs.angularjs.org/guide/controller

Comments