ruby on rails 3 - AngularJs Scope, variable value get changed -
i totally new angularjs, have taken tutorials, had been stuck last 5 hours on following problem,
i using twitterbootstrap , modal meant bootstrap modal
it show me modal once when click on slot , save worked 1st time second time, call addingbooking method initialize currentbooking object, not show modal.
this view in haml, simple showing bootstrap modal , working fine.
#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
scheduler controller;
$scope.addbooking = (slot) -> $scope.currentbooking = { name: "john doe", new: true }
bookingeditorcntl
@bookingeditorctrl = ['$scope', '$resource', ($scope, $resource) -> $scope.savebooking = (booking) -> $scope.currentbooking = null ]
directive part dom manipulation
.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')
any suggestions or thoughts please. thanks.
you haven't specified modal plugin using, little hard help. however, example, looks calling $(element).modal(keyboard: true)
multiple times. explain why you're getting error. if case, following help:
in bookingeditorctrl
:
$scope.modalinitialized = false;
in bookingeditor
directive:
if(scope.modalinitialized === false) $(element).modal(keyboard: true) $(element).modal('show')
Comments
Post a Comment