【发布时间】:2015-11-09 00:46:12
【问题描述】:
我正在尝试在脚本标签中使用ng-controller,女巫是一个模板,并且有ng-template 指令
我不知道为什么它现在起作用了
<script type="text/ng-template" id="modal-5" >
<div ng-controller="reserveModalCtrl">
<div class="modal-header">
<button type="button" class="close" ng-click="currentModal.close();"
aria-hidden="true">×</button>
<h4 class="modal-title">Rserve Shortcode</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Shortcode</label>
<input type="text" class="form-control" id="field-1"
value="30570" disabled>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-2" class="control-label">Company</label>
<div id="field-2">
<select class="form-control"
ng-model="currentShortCode.companyId">
<option ng-repeat="company in companies track by $index"
value="{{company._id}}"> {{company.companyName
+ ' (' + company.companyLatinName + ')'}}</option>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label class="control-label">Until</label>
<div>
<div class="date-and-time">
<input type="text" ng-model="currentShortCode.date"
class="form-control datepicker"
data-format="D, dd MM yyyy">
<input type="text" ng-model="currentShortCode.time"
class="form-control timepicker" data-template="dropdown"
data-show-seconds="true" data-default-time="11:25 AM"
data-show-meridian="true" data-minute-step="5"
data-second-step="5" />
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white"
ng-click="currentModal.close();">Close</button>
<button type="button" class="btn btn-info"
ng-click="currentModal.dismiss();">Reserve</button>
</div>
</div>
和我的控制器
app.controller('reserveModalCtrl', function ($scope, ShortCodeService) {
$scope.companies = ShortCodeService.companies;
$scope.shortCodes = ShortCodeService.shortCodes;
$scope.test = 'test';
});
当我在 div 元素上使用它时,它可以工作,但在这种情况下不是。
【问题讨论】:
-
所以你试试
<script ng-controller="reserveModalCtrl"? -
not working是什么意思?在您的代码中调用脚本标记的templateUrl在哪里?没有提供足够的信息。 plunker 中的演示也会有所帮助 -
@charlietfl,我认为 OP 尝试将
ng-controller指令应用于 script 标记,并看到这不起作用,但是当他萌到 div 里面时 - 一切正常跨度> -
@Grundy 我不知道这会如何工作。
ng/template用于在指令、路由或ng-include中将 ID 传递给templateUrl,如果ng-controller在脚本标签上,则永远不会暴露 -
@charlietfl,我认为 OP 只是尝试一下 :-)
标签: javascript html angularjs angularjs-directive