[英]Angular JS rendering a string as an html with trustasHtml shows error
[英]Angular JS not rendering HTML
我是Angular JS的新手。 我编写了一个简单的Angular代码,但是HTML不能正确呈现,或者表达式没有得到评估。 请帮助我所缺少的。 我正在使用angular.min.js minified(1.6)。
<!DOCTYPE html>
<html ng-app>
<head>
<script src="js/angular.min.js"></script>
<script>
function MyFirstCtrl($scope) {
var employees = ['Catherine Grant', 'Monica Grant',
'Christopher Grant', 'Jennifer Grant'];
$scope.ourEmployees = employees;
};
</script>
</head>
<body ng-controller='MyFirstCtrl'>
<h2>Number of Employees: {{ ourEmployees.length}}</h2>
</body>
</html>
使用ng-app
指令为您的应用程序设置根目录,并为您的应用程序创建一个控制器,您可以从中处理$scope
:
var app = angular.module("ng-app", []); app.controller("myCtrl", function($scope) { var employees = ['Catherine Grant', 'Monica Grant', 'Christopher Grant', 'Jennifer Grant']; $scope.ourEmployees = employees; });
<!DOCTYPE html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="ng-app"> <div ng-controller="myCtrl"> <h2>Number of Employees: {{ ourEmployees.length}}</h2> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.