我想用ng-init初始化一个字符串,以便稍后在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;});
});
当我运行代码时,ng-init中的内容不会附加到URL。你看到错误了吗?
答案 0 :(得分:0)
你的ng-init语法不正确,目前你有这个:
ng-init="module='{{x.id}}'"
你应该有这个:
ng-init="module=x.id"
希望有帮助=)