2016-06-08 12:00:00
Angular
, 2016-06-08 12:00:00

AngularJS component doesn't update models in template, where did I go wrong?

app.component('edit', {
    bindings: {
       password: '='
     },
    controller: function (dateFormat,getCurrentManager) {
        this.dateOptions = {
            dateFormat: "yy-mm-dd",
            firstDay: 1
        };
        
        this.when = "";
        this.name = "";
        this.number = "";
        this.flag = false;
       function onDataChange(date){
            var dt = {
                date : dateFormat(date)
            };
           getCurrentManager(dt).then(function(d){
               this.name = d.data[0].name;
               this.number = d.data[0].number;
            });

        }
        var secret = "8f1f44ab1c67cfef3f35db355a200444";
        function check() {
            if (md5(this.password) == secret) {
                this.flag = true;
            }
        }
        function update($http){

        }
        this.onDataChange = onDataChange;
        this.check = check;
    },
    template: [
        '<div>',
        'Введите пароль для редактирования списка <input type="text" ng-model="$ctrl.password">',
        '<button type="button" ng-click="$ctrl.check()">Редактировать</button>',
        '<div ng-if="$ctrl.flag">',
        'Введите число <input class="frm form-control" ui-date="$ctrl.dateOptions" type="text" ng-model="$ctrl.when" ng-change="$ctrl.onDataChange($ctrl.when)">',
        'Введите номер <input class="frm form-control"  ng-model="$ctrl.number">',
        'Введите имя <input class="frm form-control" type="text" ng-model="$ctrl.name">',
        '<button type="submit" class = "btn btn-danger" ng-click="$ctrl.send()">Отправить данные</button> ',
        '</div>',
        '</div>'
    ].join('')
});

Never worked with components before. When onDataChange() is called from the database, the name and number values ​​are taken by the factory, but the values ​​displayed in the view
'Введите номер <input class="frm form-control"  ng-model="$ctrl.number">',
 'Введите имя <input class="frm form-control" type="text" ng-model="$ctrl.name">',

do not change. Where I went wrong, I can not understand.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question