首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我需要用Angular在DIV标签中显示一些文本

我需要用Angular在DIV标签中显示一些文本
EN

Stack Overflow用户
提问于 2018-07-31 03:34:23
回答 1查看 1.2K关注 0票数 0

你能帮帮我吗,我对Angular一无所知。我需要在DIV标签中显示一些文本。从JS函数返回可见性条件: isShowing。文本包含HTML标签,从JS函数返回: agreementMessage。

代码语言:javascript
复制
<div ng-controller="formController" class="container" id="container">
    <div class="agreement-signed-message" ng-if="isShowing()">{{showAgreementMessage()}}</div>
</div>


function showAgreementMessage() {
    return "message";
}

function isShowing() {
    return true;
}

这是演示函数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-31 04:48:15

如果您将两个function都移动到formController,我实际上看不到您正在使用的代码有问题。

忘记将它们添加到$scope将导致您的formController无法看到它们。

代码语言:javascript
复制
var app = angular.module("Test", []);

var formController = function($scope) {

  $scope.showAgreementMessage = function() {
    return "messagesdf";
  }

  $scope.isShowing = function() {
    return true;
  }
}

app.controller(formController, ["$scope", "formController"]);

// Don't do this. Add them to formController
// function showAgreementMessage() { ... }
// function isShowing() { ... }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="Test">
  <div ng-controller="formController" class="container" id="container">
    <div class="agreement-signed-message" ng-if="isShowing()">
      {{ showAgreementMessage() }}
    </div>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51601092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档