gpt4 book ai didi

angularjs - Angular JS 表达式不评估

转载 作者:行者123 更新时间:2023-12-01 13:40:17 25 4
gpt4 key购买 nike

我写了一个简单的 Angular JS 代码。我是初学者。但是,我的一个表达式没有得到评估。需要帮忙。请检查下面的代码 -

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

myAppModule.controller('myController', function($scope){
// Hide colors by default
$scope.isHidden = true;

// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function () {
$scope.isHidden = !$scope.isHidden;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="myAppModule">
<head>
<title>Angular JS</title>
<script src="js/angular.min.js"></script>
<script src="js/myAppModule.js"></script>
<style>
body {
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
}
div {
margin: 20px;
padding: 20px;
font-size: 16px;
color:#ffffff;
}
#red {
background-color: red;
}
#green {
background-color: green;
}
#blue {
background-color: blue;
}
#purple {
background-color: purple;
}
#gray {
background-color: gray;
}
#olive {
background-color: olive;
}
</style>
</head>

<body ng-controller="myController">
<h2>AngularJS Socks</h2>
<p>Keep warm this winter with our 100% wool, 100% cool, AngularJS socks!</p>

<button ng-click="showHideColors()" type="button">
{{isHidden ? 'Show Available Colors' : 'Hide Available Colors'}}
</button>
<div id="red" ng-hide="isHidden">Red</div>
<div id="green" ng-hide="isHidden">Green</div>
<div id="blue" ng-hide="isHidden">Blue</div>
<div id="purple" ng-hide="isHidden">Purple</div>
<div id="gray" ng-hide="isHidden">Dark Slate Gray</div>
<div id="olive" ng-hide="isHidden">Olive</div>
</body>
</html>

表达式 - {{isHidden ? 'Show Available Colors' : 'Hide Available Colors'}} 没有得到评估,而是按按钮上的原样显示。不知道我错过了什么。提前致谢。

最佳答案

代码缺少右括号。您可以在此处查看工作演示 - http://jsfiddle.net/me8j3zyc/

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

app.controller('myController', function($scope) {

$scope.isHidden = true;

// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function() {
$scope.isHidden = !$scope.isHidden;
} // <- This is missing.
});

关于angularjs - Angular JS 表达式不评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40891849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com