下面是一个简单的问题:角 - 使用模板作为容器的多个模板
是否有可能在您拥有多个模板,并调用你需要的模板,当你需要它?
让我解释一下这个好一点:
我有我叫这样一个模式:
$scope.showErrorModal = ->
errorModal = $ionicPopup.show(
title: 'Issues list'
scope: $scope
templateUrl: './sections/modal/modal.tpl.html'
buttons: [{text: 'Close',type: 'button-assertive'}
])
errorModal.then (res) ->
console.log 'tapped!', res
return
return
,你可以看到,我使用的是外部的模板。
的问题是,这种方式我需要每次创建不同的模板,我的模式需要改变。
我想要做什么(如果可能的话),是能够创造内部modal.tpl.html
各个子模板,并呼吁他们在正确的模式。
下面是一些示例代码:
modal.tpl.html:
<div id="error-template">
// here the error-modal stuff
</div>
<div id="success-template">
// here the success-modal stuff
</div>
和控制器,打电话给他们这样的,例如:
$scope.showErrorModal = ->
errorModal = $ionicPopup.show(
title: 'Issues list'
scope: $scope
templateUrl: './sections/modal/modal.tpl.html#error-template' //Just to make it clear that i want to use only one part of that file
buttons: [{text: 'Close',type: 'button-assertive'}
])
errorModal.then (res) ->
console.log 'tapped!', res
return
return
这是纯粹的小说,还是有可能的?有没有其他解决方案来解决这类问题?
好如果你要有条件地呈现你的“主模板”模板内你可以使用任何指令(我的首选解决方案),或使用NG-包括和URL设置为模板。并且可以使用ng-if或ng-switch属性设置条件。 –