javascript - angularjs ng-controller doesn't work -
i'm trying work angularjs, , "ng-controller" doesn't work.
<!doctype html> <html> <head> <script type="text/javascript" src="lib/angular.js"></script> </head> <body ng-app> <h1>add user</h1> <form action="adduser" method="post"> <input type="text" name="pseudo" placeholder="pseudo"> <input type="password" name="password" placeholder="password"> <input type="submit" value="envoyer"> </form> {{1 + 2}} <div ng-controller="mycontroller"> {{ name }} </div> <a href="./remove">supression</a> <script type="text/javascript"> function mycontroller($scope){ alert("test"); $scope.name = 'toto'; } </script> </body> </html>
when i'm trying in chrome, {{1+2}}
correctly replaced '3', {{name}}
not. expected 'toto'.
i'm trying display alert on click event, , doesn't work:
<script type="text/javascript"> var myapp = angular.module('myapp', []); myapp.controller('mycontroller', ["$scope",function($scope){ $scope.name = 'toto'; $scope.onmybuttonclick = function(){ alert("test"); } }]) </script>
html
<div ng-controller="mycontroller"> {{ name }} <button ng-click="onmybuttonclick">test</button> </div>
when click, nothing happens.
try: <body ng-app>
==> <body ng-app="myapp">
in script:
angular.module('myapp', []) .controller('mycontroller', ["$scope",function($scope){ $scope.name = "toto" }])
Comments
Post a Comment