我开始学习AngularJs,我想知道为什么我的代码无法正常工作?我想知道为什么h1
标签没有随着橙色而变橙色ng-class="'orange'"
。
我知道答案可能很简单,但我才刚刚开始。
这是我的index.html:
<html ng-app="app">
<head>
<style type="text/css">
</style>
</head>
<body>
<div ng-controller="MainController">
<h1 ng-class="'orange'">Hello There</h1>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
这是我的app.js:
var app = angular.module('app', []);
app.controller('MainController', function($scope) {
})
ps在控制台中没有错误。
它必须工作。因为结果是您给类作为直接string
变量,所以该值orange
带有单引号。
与您定义类似范围变量一样,该变量从as返回值
<h1 ng-class="class">Hello There</h1>
代码
$scope.class='orange';
两种方法是同一件事。
更新
您需要添加CSS类来获取这些更改
<style type="text/css">
.orange {
color: orange;
}
</style>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句