Javascript-форум (https://javascript.ru/forum/)
-   Angular.js (https://javascript.ru/forum/angular/)
-   -   Калькулятор (this vs scope) (https://javascript.ru/forum/angular/69544-kalkulyator-vs-scope.html)

shoopik 02.07.2017 13:39

Калькулятор (this vs scope)
 
Всем привет, начал изуать ангуляр, нашел код простенького калькулятора со $scope, при изменении его на this функция не работает. Точнее не выводит результат. Получается везде стер $scope, и вместо него подставил this. Не догоняю почему не выводит result. :-?
var app = angular.module('myApp', []);

app.controller('CalculatorController', function() {
        this.result = function() {
            if (this.operator == '+') {
                return this.a + this.b;
            }
            if (this.operator == '-') {
                return this.a - this.b;
            }
            if (this.operator == '*') {
                return this.a * this.b;
            }
            if (this.operator == '/') {
                return this.a / this.b;
            }
        };
    });

destus 02.07.2017 14:16

shoopik,
https://plnkr.co/edit/eLFy99qOM6ibqiSzISaY?p=preview

shoopik 02.07.2017 14:43

Цитата:

Сообщение от destus (Сообщение 457218)

Спасибо, понял в чем проблема была :yes:


Часовой пояс GMT +3, время: 08:14.