1
我正在学习Angular JS,我写了一个超级简单的代码片段,但它似乎并没有正常工作。 Here is the Plunker,代码看起来像这样。我知道Angular正在工作,因为双曲线括号中的表达式是在HTML({{3 * 14}} = 42)中评估的。问题在于,跨度中的文本应该根据输入中的值进行更改,因此如果它可以被2整除,则为粗体等等。所以看来问题是它不会使用我的自定义JavaScript模块。有没有什么办法解决这一问题?简单的角JS模块不工作,但大师的角脚本工作
//script.js
var root = angular.module('root', []);
root.controller('index', ['$scope', function($scope){
$scope.value = 1;
$scope.isBold = function(){
return $scope.value % 2 === 0;
};
$scope.isItalic = function(){
return $scope.value % 3 === 0;
};
$scope.isUnderlined = function(){
return $scope.value % 5 === 0;
};
}]);
<!-- index.html -->
<!DOCTYPE html>
<html ng-app="root">
<head>
<link rel="stylesheet" type="text/css" href="style2.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div ng-controller="index">
<input type="text" ng-model="value"/>
<span ng-class="{bold: isBold(), italic: isItalic(), underline: isUnderlined()}">Example Text</span>
<span>{{3*14}}</span>
</div>
</body>
</html>
请包括此演示也请[Plunkr](https://plnkr.co/edit/cnbuVKYsuYAfGzGLorcp?p=preview) –
谢谢。这工作,这里是新的演示。 https://plnkr.co/edit/UzTuYhEbE0vQY1w8iUm9?p=preview –