1

각도 1.5로 작성한 각도 구성 요소가 있습니다. 다음과 같이 보입니다 :각 구성 요소에 동적으로 templateUrl 할당

var module = angular.module("ncRelationshipSearch"); 

module.component("relationshipSearch", { 
    templateUrl: <need to dynamically assign>, 
    controllerAs: "vm", 
    controller: ['config', function(config){ 
     ... config provider here knows about templateURL... 
    } 
} 

어떻게 든 할당 할 수있는 templateUrl이 필요합니다. URL을 제공 할 수있는 공급자가 config이지만 구성 요소 정의 시점에 삽입 할 수 없습니다. 바인딩을 통해 URL을 가져 오거나 컨트롤러에서 나중에 설정하는 방법이 있습니까?

답변

3

service/factory을 주입 할 수있는 templateUrl의 기능을 가질 수 있습니다. 실제로 templateUrl 함수를 통해 config 공급자를 주입 할 수 있습니다.

module.component("relationshipSearch", { 
    templateUrl: function(config){ 
     //play here with service variables generate templateUrl 
     //other code can also lie here. :) 
     return config.myTemplatUrl; 
    }, 
    controllerAs: "vm", 
    controller: ['config', function(config){ 
     ... config provider here knows about templateURL... 
    } 
} 
관련 문제