2015-06-05 74 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> 

你可以試試這個代碼我檢查這個代碼工作正常,我也使用此代碼