A
A
Aizharik2015-05-07 14:08:16
JavaScript
Aizharik, 2015-05-07 14:08:16

Angular ng-click not working?

Hello!
I started learning Angular, I can't figure out why ng-click doesn't work for me from the example, here's the HTML code:

<!DOCTYPE html>
<html lang="ru" ng-app="myApp">
<head>
  <meta charset="UTF-8">
  <title>Angular JS</title>

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
</head>
<body ng-controller="MainController">
  Name: <input type="text" ng-model="name"><br />
  Hello, {{ name }}!<br />

  <input type="button" value="Click" ng-click="myFunc">
  <script type="text/javascript" src="/app.js"></script>
</body>
</html>

Here is app.js:
var app = angular.module("myApp", []);

app.factory('MyLogginService', function(){
  return {
    log: function(argument){
      console.log(argument);
    }
  };
});

app.factory('AlertLogginService', ['$window', function($window){
  return{
    log: function(argument){
      $window.alert(argument);
    }
  };
}]);

app.controller('MainController', ['$scope', 'AlertLogginService', function($scope, logger){
  $scope.name = "Guest";

  $scope.myFunc = function(){
    logger.log('hello!');
  };
}]);

It works in the example, but I don't. What could be the problem? Angular errors are not displayed in the browser console.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aizharik, 2015-05-07
@aizhar777

I figured it out, all I had to do was add the parenthesis "()" at the end and it worked right away.

<input type="button" value="Click" ng-click="myFunc()">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question