我有這樣的代碼:如何做angularjs if語句?
<html>
<head>
</head>
<div ng-app="" ng-controller="Test">
<input type="text" ng-model="inputty">
<p>{{output}}</p>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script>
function Test($scope){
if($scope.inputty=="Hello") {
$scope.output="OK!";
} else {
$scope.output="NOT OK!";
}
}
</script>
</html>
但它不工作時,NOT OK!
顯示器。但它就像if語句不能從inputty
讀取。所以當我在輸入框中輸入Hello
時,它應該顯示OK!
。
'$ scope.output = function(){return $ scope.inputty ==「Hello」?「OK!」 : 「不好!」; }'並且'
{{output()}}
' – PSL 2014-09-10 19:20:44