我对 AngularJs 完全陌生,我上过教程,我在过去 5 个小时里一直被以下问题困住,
我正在使用 twitterbootstrap 和模态我的意思是引导模态
当我单击插槽并保存时,它向我显示一次模态,第一次但第二次工作,它调用 addBooking 方法初始化 currentBooking 对象,但不显示模态。
这是我在 haml 中的观点,简单地显示引导模式及其工作正常。
#scheduler{ :'ng-controller' => 'SchedulerCtrl', :scheduler => true, :data =>{:interval => @interval, :restaurant_id => @restaurant_id} }
#booking-editor.modal.hide.fade{ :'aria-hidden' => true, :'aria-labelledby' => "bookingEditorLabel", :role => "dialog", :tabindex => "-1", :'booking-editor' => 'currentBooking', :'ng-controller' => 'BookingEditorCtrl' }
.modal-body
%input{ :type => "text", :'ng-model' => "currentBooking.name" }
.modal-footer
%button.btn{ :'aria-hidden' => true, :'data-dismiss' => "modal" } Close
%button.btn.btn-primary{ :'ng-click' => 'saveBooking(currentBooking)' } Save Booking
调度器控制器;
$scope.addBooking = (slot) ->
$scope.currentBooking = { name: "John Doe", new: true }
BookingEditorCntl
@BookingEditorCtrl = ['$scope', '$resource', ($scope, $resource) ->
$scope.saveBooking = (booking) ->
$scope.currentBooking = null
]
DOM 操作的指令部分
.directive 'bookingEditor', ->
restrict: 'A'
link: (scope, element, attrs, ctrl) ->
scope.$watch attrs.bookingEditor, ->
if scope[attrs.bookingEditor]
$(element).modal(keyboard: true)
$(element).modal('show')
else
$(element).modal('hide')
请有任何建议或想法。谢谢。