2015-10-14 75 views
-3

我想学习角度,但有一些例子谁不工作(我使用4.7版)。为什么这个角度js中的表达式不显示任何内容?

这里:

  <div ng-app="direttive" ng-controller="addizione"> 
       <b>Ng-bind result addiction by two model</b><br/><br/> 
       Numero1 = <input type="number" name="input" ng-model="example.numerouno" min="0" max="99" required><br/> 
       Numero2 = <input type="number" name="input" ng-model="example.numerodue" min="0" max="99" required><br/> 
       <p>addizione: {{example.numerouno}}</p> 
      </div> 
       angular.module('direttive',[]); 
       .controller('addizione', ['$scope',function($scope){ 
       $scope.example = { 
        numerouno: 12 
        numerodue: 7 
       }; 
      }]); 

当我尝试使用浏览器的可视化我没有看到任何数字或wxpression,应该有人告诉我,我错了吗?

+1

在哪里体现?你想添加两个数字吗? –

+1

您将100%在控制台中看到javascript错误(或2!)。 – Jamiec

回答

0

我想你想两场的总和。 请检查: HTML

<div ng-app="direttive" ng-controller="addizione"> 
<b>Ng-bind result addiction by two model</b><br/><br/> 
Numero1 = <input type="number" name="input" ng-model="example.numerouno" min="0" max="99" required><br/> 
Numero2 = <input type="number" name="input" ng-model="example.numerodue" min="0" max="99" required><br/> 
<p>addizione: {{total}} </p></div> 

JS:

var app = angular.module('direttive', []); 
app.controller('addizione', ['$scope','$http', function($scope, $http){ 

$scope.example = {"numerouno": 12, "numerodue": 7}; 

$scope.total = $scope.example.numerouno + $scope.example.numerodue;}]); 

codepen:http://codepen.io/anon/pen/yYzOOZ

+1

解释*你已经改变了什么(和*为什么*你改变了它)通常很有用,而不是只发布一个工作版本! – Jamiec

+0

当然,我会在更新 –

0

angular.module('direttive',[]);的末尾删除分号,它会起作用。

1
angular.module('direttive',[]); 
        .controller('addizione', ['$scope',function($scope){ 

从模块监守controller删除;直接绑定到它。

angular.module('direttive',[]) 
       .controller('addizione', ['$scope',function($scope){ 

另一个是

$scope.example = { 
        numerouno: 12 
        numerodue: 7 
       }; 

使用,用于对象的多个键和值。

检查工作fiddle

+0

真的很感谢你,这只是一个语法问题! –

+0

总是首先检查控制台错误..它告诉很多事情要自己解决问题.. –

相关问题