It doesn't work to link the model through this.



  • Looked at "the best practice of angular," and there's a counteraller template. введите сюда описание изображения

    I'm doing the following:

    (function (angular) {
    angular
        .module('test', []);
    

    angular
    .module('test')
    .controller('countryCtrl', countryCtrl);

    //countryCtrl.$inject = ['$scope'];

    function countryCtrl() {
    var vm = this;
    vm.country = {
    name: 'Ukraine',
    area: '603 628',
    population: '42 825 883',
    capital: {
    name: 'Kiev'
    }
    };
    }
    })(angular);

    Verst:

    <div class="box" ng-controller="countryCtrl">
    <h1 class="h1">Страна: {{this.country.name}}</h1>
    <p>Площадь: {{this.country.area}}</p>
    <p>Население: {{this.country.population}}</p>
    <p>Столица: {{this.country.capital.name}}</p>
    </div>

    There's nothing out there that I'm not doing that?



  • This opportunity, the use of a controller instead of a staple, was presented in 1.1.5 and was named: controller As Synthaxis

    It allows for the designation of alias controller and direct reference to the properties and functions of the counteraller.

    This requires a description of the ng-controller Attribute tolias.

    ng-controller="ControllerName as alias"
    

    usually as alias points vm reduction from view model

    In your case: ng-controller="countryCtrl as vm"

    In addition, reference may be made to the characteristics of the counteraller

    <h1 class="h1">Страна: {{vm.country.name}}</h1>
    

    It's worth remembering that the cop isn't missing, and this It's the scope, and the scope adds a field with the same name as the aliath pointing to the counterfoiler.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2