Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damian Green 452 posts 1433 karma points
    Nov 19, 2014 @ 23:14
    Damian Green
    0

    Odd angular model binding going on

    Quick question on model binding.

    I am buiding a custom dashboard in the backend (based on Tims People tree - https://github.com/TimGeyssens/UmbracoAngularBackofficePages/blob/master/TestSite/App_Plugins/Example/backoffice/peopleTree/edit.controller.js)

    I am not using a full person object like the example but a simple string that is on my model - searchterm.

    I have textbox and it display the default i set in the model. When i edit the textbox the value on the scope is not updating but if i add a second textbox and set it to the same model variable it updates as i type.

    The only way i have gotten to update the model value on the scope is to add a change event on the textbox, pass in the model value from the view and update the scope!

    Driving me nuts as to why!! Any ideas??

    Here is the bit from the view

     <umb-control-group label="Search Term" description="Enter serach term'">
                        <input type="text" class="umb-editor umb-textstring" ng-model="searchTerm" ng-change="changed(searchTerm)" required />
    
                        <br/>
                        scope = {{ searchTerm}} ..
                        <input ng-model="searchTerm"/>
                    </umb-control-group>
    

    Here is the controller:

    angular.module("umbraco").controller("MemberLocate.MemberLocateEditController",
    function ($scope, $routeParams, memberLocateResource, notificationsService, navigationService) {
    
        console.log('scope triggered');
    
        $scope.loaded = false;
        $scope.members = {};
        $scope.searchTerm = "roger";
        $scope.searchType = "AccountNumber";
    
        if ($routeParams.id == -1) {
            $scope.searchTerm = "test 2";
            $scope.members = {};
            $scope.loaded = true;
        }
    
        $scope.loaded = true;
        $scope.searchDone = false;
    
        $scope.changed = function (val) {
            $scope.searchTerm = val;
            console.log('val=' + val);
            console.log('changed' + $scope.searchTerm);
        };
    
        $scope.search = function () {
    
            console.log('search term=' + $scope.searchTerm);
            console.log('search type=' + $scope.searchType);
    
            memberLocateResource.findByUsername($scope.searchTerm).then(function (response) {
    
                $scope.members = response.data;
                $scope.memberLocateForm.$dirty = false;
                $scope.searchDone = true;
                //navigationService.syncTree({ tree: 'peopleTree', path: [-1, -1], forceReload: true });
                //notificationsService.success("Success", person.firstName + " " + person.lastName + " has been saved");
            });
        };     
    });
    
  • Dave Woestenborghs 3429 posts 11693 karma points MVP 7x admin c-trib
    Dec 01, 2014 @ 15:20
    Dave Woestenborghs
    0

    You have a error in your view. You have {{ searchTerm}}. This should be {{searchTerm}} without the leading space.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft