0

i'm asking for your help. I'm an AngularJS begginer and components bindings looks like esotherical for me. I don't really understand why my variables a sets to undefined.

Could you help me please ?

Here is my HTML :

<div ng-controller="mapController as map" style="text-align:center;">
    <div>{{map.lastClickedCountry}}</div>
    <risk-map lastClickedCountry="map.lastClickedCountry"
              countriesUnits="map.countriesUnits">
    </risk-map>
</div>

My Component JS :

angular.module('riskApp').component("riskMap", {
    bindings: {
        lastClickedCountry: '=',
        countriesUnits: '='
    },
    templateUrl: 'template/risk.html',
    controller: function ($scope) {
        this.$onInit = function () {
            console.log("onInit")
            console.log(this);
            console.log($scope);
        };

        this.$onChanges = function () {
            console.log("onChange")
            console.log(this);
            console.log($scope);
        };

        this.setArrivant = function (pays, nombreArrivant) {
            this.countriesUnits[pays].arrivant = nombreArrivant
        }

        this.setStationnaire = function (pays, nombreStationnaire) {
            this.countriesUnits[pays].stationnaire = nombreStationnaire
        }


        this.getArrivant = function (pays) {
            return this.countriesUnits[pays].arrivant
        }

        this.getStationnaire = function (pays) {
            return this.countriesUnits[pays].stationnaire
        }

        this.click = function (country) {
            console.log("Dernier pays : " + this.lastClickedCountry)
            console.log("Pays click : " + country)
            console.log(this)
            this.lastClickedCountry = country;
        }
    }
})

My Controller JS:

angular.module('riskApp').controller('mapController', function 
CountCtrl($scope) {
    this.lastClickedCountry = "test";
    this.countriesUnits = {}
})
2
  • 1
    There is a syntax error here: this.countriesUnits = {); Commented Dec 23, 2019 at 11:22
  • Syntax error fixed, by still the same bug Commented Dec 23, 2019 at 11:25

1 Answer 1

2

Attributes bindings need to be in kebab-case:

<div ng-controller="mapController as map" style="text-align:center;">
    <div>{{map.lastClickedCountry}}</div>
    <risk-map last-clicked-country="map.lastClickedCountry"
              countries-units="map.countriesUnits">
    </risk-map>
</div>

For more information, see

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.