![](/img/trans.png)
[英]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.