为什么Angular不会启动?

时间:2017-01-18 11:58:55

标签: angularjs initialization

我只是用angular 1.x做一些简单的练习,但浏览器没有在括号内渲染值和函数,有什么不对?

HTML

<body ng-app="LandingApp">

    <form ng-controller="LandingApp">
        <input type="number" ng-model="numeroaltrepagine">{{numeroaltrepagine}}</input>
        <b>TOTALE</b><br/>
        {{totale() | currency}}
    </form>

    <b>TOTALE</b>



</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="js/main.js"></script>  

这里是js

   var LandingApp = angular.module('LandingApp',[]);

LandingApp.controller('numberpages',function($scope){

    $scope.primapagine = 150;
    $scope.altrepagine = 90;
    $scope.numeroaltrepagine = 1;

    $scope.totale = function(){
        return $scope.altrepagine * $scope.numeroaltrepagine;
    }
});

1 个答案:

答案 0 :(得分:0)

您的控制器应 numberpages 而不是 LandingApp

<form ng-controller="numberpages">

<强>样本

var LandingApp = angular.module('LandingApp',[]);
LandingApp.controller('numberpages',function($scope){
$scope.primapagine = 150;
$scope.altrepagine = 90;
$scope.numeroaltrepagine = 1;

$scope.totale = function(){
    return $scope.altrepagine * $scope.numeroaltrepagine;
}
});
<!DOCTYPE html>
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>   
</head>

<body ng-app="LandingApp">

    <form ng-controller="numberpages">
        <input type="number" ng-model="numeroaltrepagine">{{numeroaltrepagine}}</input>
        <b>TOTALE</b><br/>
        {{totale() | currency}}
    </form>

    <b>TOTALE</b>



</body>

</html>