【发布时间】:2017-09-07 16:22:05
【问题描述】:
我是创建 AngularJS 样式代码的新人。我正在尝试以 AngularJS 格式重新创建现有网站。
我终于想出了如何在外部文件中制作应用程序/控制器并赋予控制器功能。然后我可以让这些函数返回变量,尤其是字符串,以在我的 .html 文件中填充信息,但是当我使用 html 标记时,它们在 .html 中用作文字。
我正在尝试找出如何以类似的方式填充我的 html 模板,但 html 可以正常工作。
在其他 JS 格式中,我可以写入文档/响应,或者至少让函数返回一个值,然后让原始 JS/HTML 将该返回值写入 html。
我正在尝试在页脚中进行类似的操作,但 Footer() 有一个字符串需要显示在两行中。
要遵循的示例代码(我将把它编辑到重要的部分): HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script language="JavaScript" src="./Universal.js" runat="server"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="./Main.css" rel="stylesheet" type="text/css">
</head>
<body id="idBody" ng-app="Universal">
<table id="idTableMain">
<tr id="idFooterRow">
<td id="idFooterMain" colspan="3">
<p id="idFooterContent" ng-controller="UniversalController">
{{Footer()}}
</p>
<p id="idFooterManagement" ng-controller="UniversalController">
{{WebMaster()}}
</p>
</td>
</tr>
</table>
</body>
</html>
应用程序/控制器:
var Universal = angular.module("Universal", []);
Universal.controller("UniversalController", ['$scope', function ($scope)
{
$scope.Footer = function()
{
$scope.vResult = "© Copyright 2012 All rights reserved<br>";
$scope.vResult += "House That Kamurai Built";
return $scope.vResult;
};
$scope.WebMaster = function()
{
$scope.vResult = "Website managed by Kamurai.";
return $scope.vResult;
};
}]);
【问题讨论】:
标签: html angularjs function controller