Wallcraft Wallcraft - 4 months ago 10
AngularJS Question

I dont understand why my code wont works

Hi all i'm approaching to AngularJS, it seemed to be easy, but i understood that it isn't.
I want to do a simple login without authentication, just a login that you insert username and passowrd, click on the login button and a message appears and notify you that you have logged in.
I gave a look at the documentation and i write this code

<!DOCTYPE html>
<html>
<head>
<title>Login Prova</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body>
<h1>Login</h1>
<div ng-app="mainApp" ng-controller="AppController">
Inserisci username<input type="text" ng-model="username1">
Inserisci password<input type="password" ng-model="password">
<button ng-click="stampa()">Click!</button>
<p>Ciao {{result}}</p>
</div>
<script>
var mainApp = angular.model("mainApp",[]);
mainApp.controller('AppController',['$scope', function($scope){
$scope.result = null;
$scope.stampa = function(){
$scope.result = "Logged in";
}
}]);
</script>
</body>
</html>


Thanks you all for the possibile solution.

Answer

You have a typo. There is no angular.model function. You meant to put angular.module.

var mainApp = angular.module("mainApp",[]);