I want to initialize a string with ng-init to append it later on a URL.
HTML
<div class="container">
<div class="panel-group" id="accordion" ng-app="myApp" ng-controller="moduleCtrl">
<div class="panel panel-default" ng-repeat="x in modules">
<div class="panel-heading" >
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#{{ x.id }}">{{ x.name }}</a>
</h4>
</div>
<div id="{{ x.id }}" class="panel-collapse collapse" ng-controller="termCtrl" ng-init="module='{{x.id}}'">
<ul class="list-group">
<li class="list-group-item" ng-repeat="y in terms">{{ y.name }}</li>
</ul>
</div>
</div>
</div>
</div>
JS
var app = angular.module('myApp', []);
app.controller('moduleCtrl', function($scope, $http) {
$http.get("http://wirtschaftsinformatik.web2page.ch/selectModuleForWebApp.php")
.then(function (response) {$scope.modules = response.data.records;});
});
app.controller('termCtrl', function($scope, $http) {
$scope.url = "http://wirtschaftsinformatik.web2page.ch/selectTermForWebApp.php?id_module="+$scope.module;
$http.get($scope.url)
.then(function (response) {$scope.terms = response.data.records;});
});
When I run the code the content inside ng-init doesnt append to the URL. Do you see the error?
Your ng-init syntax in incorrect, currently you have this:
ng-init="module='{{x.id}}'"
You should have this:
ng-init="module=x.id"
Hope it helps =)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.