Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$scope not working #34

Closed
zibrohimov opened this issue Dec 15, 2015 · 4 comments
Closed

$scope not working #34

zibrohimov opened this issue Dec 15, 2015 · 4 comments

Comments

@zibrohimov
Copy link

Thanks for your hard work and this is saving a lot of my time. However, I've a very small issue for now, which I belive can be fixed easily.

What I'm trying to do is adding and updating an object using bootbox modal. I'm using .dialog() with custom template, which contains some form input elements. I tried to work with $rootScope. When doing insert, updates to input fields are updating the $rootScope.myObject well and there is no problem. But when doing an update, I sould populate the form with current values and thus I'm updating the $rootScope.myObject. I'm doing this with ng-click, because I don't see other way of doing it, becuase before opening the bootbox modal, I should first get the object from database, by id, then update $rootScope. This is not working. In update mode, the fields are not populating with values. Belov is my code sample.

BootBox Options

$scope.modalOptions = {
    closeButton: false,
    buttons: {
        warning: {
            label: "Cancel",
            className: "btn-default"
        },
        success: {
            label: "Save",
            className: "btn-danger",
            callback: function () {
                //add or update
            }
        }
    }
}

BootBox

<a title="Edit" href="" 
    ng-click="update(id)"                                                         
    ng-bootbox-custom-dialog
    ng-bootbox-custom-dialog-template="/template.html"
    ng-bootbox-options="modalOptions">Update This</a>

Template.html

<form ng-controller="myController">
    <input type="text" ng-model="myObject.Name" />
    <input type="text" ng-model="myObject.Quantity" />
</form>

$scope.update(id)

$scope.update= function (id) {
    var objFromDatabase = //getting object from db by id
    $rootScope.myObject = objFromDatabase;
};

$rootScope.myObject

$rootScope.myObject = {
    Name: '',
    Quantity: ''
}

When I click "Update This" link, the modal is showing up with custom html/form, but textboxes are empty. Values are not there. Please help.

@vlapo
Copy link
Contributor

vlapo commented Dec 15, 2015

Hi,

what about "getting object from db by id"? Try assign object { Name: 'test', Quantity: 'qtytest' } to objFromDatabase variable in $scope.update function instead use db service

I just reproduce your code on localhost and I see values in dialog inputs.

@zibrohimov
Copy link
Author

Sorry I didn't notice that there is a 'scope' property in the options. I've found it in #22. It now works fine.

@vlapo
Copy link
Contributor

vlapo commented Dec 15, 2015

Glad to hear that I helped you. Its okey, there is no documentation about scope property (#23). Please mark issue close if you solved your problem ;)

@vlapo
Copy link
Contributor

vlapo commented Dec 22, 2015

@zibrohimov please close issue if your problem is solved :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants