ng-repeat on ng-select with onChange function repeats the same values

106 views
Skip to first unread message

Sasi Gowd

unread,
Jan 14, 2015, 5:19:16 PM1/14/15
to ang...@googlegroups.com

here is my example http://plnkr.co/edit/oGnKUmg3LHE3wlkGrsqp?p=preview

Hi I would like to display port-number and attributes when ever i call onchange function in the ng-select, in the above example every time i click add button the add new connection form will create and when ever i select the select options the port number and instance connection attributes are changed depends on the select option, but the when ever i sect the select option the port number and instance creation attributes changes on every new connection , any help ?

see screen shots : ![enter image description here][1] ![enter image description here][2]

angular.module('Test', [])
.controller('testctr', function($scope){

  $scope.connectionArray = {connectionTypeResource1: [] };
    $scope.addNewConnections = function () {
        $scope.connectionArray.connectionTypeResource1.push({});
        $scope.$apply();
    };
    $scope.removeSubConnection = function (index) {
        $scope.connectionArray.connectionTypeResource1.splice(index, 1);
    };
    $scope.getConnectionTypeResource1= function (type, id) {
        console.log(type);
        $scope.connectionTypeResource11 = connectionsResource.getConnectionsResource().customGET('config', {type: type}).$object;
        $scope.connectionTypeResource11.instanceId = $scope.uInstance.id;
        console.log($scope.connectionTypeResource11)
    };
    $scope.connectionTypes = [
        {name: 'VERTICA'},
        {name: 'SFTP'},
        {name: 'QUEUE'},
        {name: 'REST'},
        {name: 'CDMADMIN'},
        {name: 'CDMAPI'},
        {name: 'MYSQL'}
    ];



});


  [1]: http://i.stack.imgur.com/h1737.png
  [2]: http://i.stack.imgur.com/XkMlL.png

Sander Elias

unread,
Jan 15, 2015, 1:27:01 AM1/15/15
to ang...@googlegroups.com

Hi Sasi,

You have a problem with the inheritance of the scope. you are reusing the same scope variable inside your nested (ngRepeat creates new scopes)
So your connType will point to the same variable, until it is used inside your repeat.
You really should be using connectionTypeResource1.connType inside your repeater. (same issue but the other way arround for connectionPort.port!)

Regards
Sander

Sasi Gowd

unread,
Jan 15, 2015, 5:56:39 PM1/15/15
to ang...@googlegroups.com, sande...@gmail.com
Hi Sander,

Thanks for responding to my post, i little bit confused could you please elaborate your answer ? 

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/33Q8R0wrYms/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Jan 16, 2015, 1:51:36 AM1/16/15
to ang...@googlegroups.com, sande...@gmail.com
http://plnkr.co/edit/bNpeTYnsIjkp6T2ufAX2?p=preview

I updated your plunker a bit, it's not entirely done, but you should get the picture.
When you still have questions, don't hesitate to ask!

Regards
Sander
Reply all
Reply to author
Forward
0 new messages