Mr Smith Mr Smith - 6 months ago 72
AngularJS Question

Problems with angular-modal-service

I'm trying to use the angular modal service to display a modal with an inline template, but I get an error. What am I missing? I just want to display a simple message in the modal. Here is the fiddle: http://jsfiddle.net/qhcsg6Lk/

Page



<script src="https://rawgit.com/dwmkerr/angular-modal-service/master/dst/angular-modal-service.js"></script>

<div class="container" ng-app="app" ng-controller="Controller">

<h3>Angular Modal Service</h3>
<a class="btn btn-default" href ng-click="show()">Show a Modal</a>

</div>


Controller

var app = angular.module('app', ['angularModalService']);

app.controller('Controller', function($scope, ModalService) {

$scope.test="outer scope"
$scope.show = function() {
ModalService.showModal({
template: "{{test}}",
controller: function() {
this.test="test scope";
},
controllerAs : "modal"
})
}
})


ERROR:

enter image description here

Win Win
Answer

You want to access test as {{modal.test}} since you have controllerAs syntax.

http://jsfiddle.net/jvara30w/

According to the documentation here, if you use template, you will need to provide raw HTML.

template: "<div>{{modal.test}}</div>",
Comments