【发布时间】:2014-09-16 23:04:26
【问题描述】:
我有一个应用程序使用了一个独立的指令,无论如何都与应用程序无关 但可以从任何地方使用 $scope.$emit() 调用。我希望它根据从控制器中的 $scope.$on() 函数接收到的产品 ID 加载内部动态模板。
这是我目前所拥有的简化版本...
index.html
<div quote-application ng-show="ifActive"></div>
path/to/template.html
<form class="application-modal">
<button>X</button>
<!-- this is what i would like to by dynamically loaded -->
<fieldset product="{{productID}}"></fieldset>
<button>Add Product</button>
<button>Cancel</button>
</form>
JS 文件
angular.module('client.quote-app', [])
.controller('quoteCtrl', ['$scope', function($scope) {
$scope.ifActive = false;
$scope.productID = '0000';
$scope.$on('requestQuote', function(event, productID) {
$scope.ifActive = true;
$scope.productID = productID; //this is coming through okay
});
}])
//this loads fine
.directive('quoteApplication', function() {
return {
controller : 'quoteCtrl',
templateUrl : 'path/to/template.html'
}
})
//not sure what to do here ...
.directive('product', function() {
return {
//<!-- I want this to load a template
based off of the productID every
time $scope.on() gets called --!>
templateUrl : 'path/to' + productID + '.html'
}
})
【问题讨论】:
标签: javascript angularjs templates dynamic angularjs-directive