programing

src 변수를 사용한ng-module

codeshow 2023. 3. 28. 22:20
반응형

src 변수를 사용한ng-module

ng-includes src를 변수로 변경하고 싶습니다.현재 제가 가지고 있는 것은 이것입니다.

 <div class='alignRightCenter' id='rightContent'>
    <ng-include src="'{{view}}'"> </ng-include>
</div>

컨트롤러는 다음과 같습니다.

ctrl.controller('contentCtrl', ['$scope', function($scope) {
      $scope.view = "partials/setListName.tpl.html";
  }]);

유감스럽게도 ng-view는 이미 이 페이지로 이동하기 위해 사용되고 있기 때문에 사용할 수 없습니다.이런 일을 할 수 있을까요?

다음과 같이 시도합니다.

<ng-include src="view"> </ng-include>

---------------------------------------------

이렇게 하면 돼요.

표시:

<div data-ng-include data-ng-src="getPartial()"></div>

컨트롤러:

function AppCtrl ($scope) {
  $scope.getPartial = function () {
      return 'partials/issues.html';
  }
}

이것처럼.JavaScript에서처럼 작은 따옴표와 +를 사용해야 합니다.

<ng-include src="'/path/to/template'+ my.variable +'.html'"></ng-include>

언급URL : https://stackoverflow.com/questions/21860225/ng-include-with-a-variable-for-src

반응형