我在Demo上有一个简单的代码文件
我正在尝试使用ng-bind=""
和ng-init
,但两个人都没有工作。基本上我必须在{{1}}上显示一些数据。
答案 0 :(得分:1)
你实际上错过了这个,
<div ng-app="myApp.controllers" ng-controller="Report as ctrl">
<强>样本强>
angular.module("myApp.controllers", []);
(function(angular) {
"use strict";
function Report($scope) {
let ctrl = this;
ctrl.reports = "Rolys Royc H87H";
$scope.reportInfo = "Aircraft";
ctrl.$onInit = function() {
$scope.reportInfo = "Aircraft";
};
}
Report.$inject = ["$scope"];
angular.module("myApp.controllers").controller("Report", Report);
})(angular);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<head>
<title>AngularJS Directives</title>
</head>
<body>
<h1>Sample Application</h1>
<div ng-app="myApp.controllers" ng-controller="Report as ctrl">
<h4 ng-bind="ctrl.reports"></h4>
<h4 ng-bind="reportInfo"></h4>
</div>
</body>
</html>
&#13;
答案 1 :(得分:0)
这很有效。您尚未指定ng-app
或ng-controller
代码:
<html>
<head>
<title>AngularJS Directives</title>
</head>
<body>
<h1>Sample Application</h1>
<div ng-app="myApp.controllers" ng-controller="Report as ctrl">
<h4 ng-bind="ctrl.reports"></h4>
<h4 ng-bind="reportInfo"></h4>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="a.js"></script>
<script src="abc.js"></script>
</body>
</html>