2016-12-01 31 views
0

我想用ng-init初始化一個字符串,以便稍後將其附加到URL上。AngularJS:將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

你的NG-初始化語法,目前你有這樣的:

ng-init="module='{{x.id}}'" 

你應該有這樣的:

ng-init="module=x.id" 

希望它可以幫助=)

+0

THX,我想這一點但沒有工作太...我需要{{x.id}}表達式,因爲我從其他angularjs數組中獲取數據。 –