Reputation: 115
Could you help me, i have not knowledge of Angular. I need to show some text in DIV tag. Visibility condition is returning from JS function: isShowing. Text contains HTML tags and is returning from JS function: agreementMessage.
<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;
}
This is demo functions.
Upvotes: 1
Views: 4885
Reputation: 3231
You need to use $scope
to invoke the function from your HTML (View) to your controller by binding:
function DemoCtrl($scope) {
$scope.showAgreementMessage = function() {
return "message";
}
$scope.isShowing = function() {
return true;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="DemoCtrl" ng-app>
<div class="agreement-signed-message" ng-if="isShowing()">{{showAgreementMessage()}}</div>
</div>
Upvotes: 1
Reputation: 3166
I actually don't see a problem with the code you are using if you move both the function
s to the formController
.
Forgetting to add them to $scope
will cause your formController
to not be able see them.
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() { ... }
<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>
Upvotes: 2