2015-06-05 44 views
0

我写了这个代码输出不是angular.js文件

<html ng-app> 
    <head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> 
<script> 
angular.module('scopeExample', []) 
.controller('MyController', ['$scope', function($scope) { 
    $scope.username = 'World'; 

    $scope.sayHello = function() { 
    $scope.greeting = 'Hello ' + $scope.username + '!'; 
}; 
}]); 
</script> 
</head> 
<body> 
<div ng-controller="MyController" > 
Your name: 
<input type="text" ng-model="username"> 
<button ng-click='sayHello()'>greet</button> 
<hr> 
{{greeting}} 
</div> 
</body> 
</html> 

在地方采取从输入文本框,它只是打印{{问候}},甚至在文本框中没有与世界正确初始化。

回答

1

集之上HTML标记ng-app ="scopeExample"

0

定义你的NG-应用= “scopeExample”,Fiddle

angular.module('scopeExample', []) 
.controller('MyController', ['$scope', function($scope) { 
    $scope.username = 'World'; 

    $scope.sayHello = function() { 
    $scope.greeting = 'Hello ' + $scope.username + '!'; 
}; 
}]); 
0
function HelloCntl($area) { 
    $area.test= 'Demo'; 
} 
<div ng-controller="MyController"> 
    Your name: <input type="text" ng-model="test"/> 
    <hr/> 
    Hello {{test|| "Demo"}}! 
</div> 

你可以试试这个代码我检查这个代码工作正常,我也使用此代码