首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS 1.7.9将变量从控制器绑定到组件,提供未定义的值

问AngularJS 1.7.9将变量从控制器绑定到组件,提供未定义的值
EN

Stack Overflow用户
提问于 2019-12-23 11:00:57
回答 1查看 492关注 0票数 0

我在寻求你的帮助。我是AngularJS乞丐,组件绑定对我来说就像是等温线。我真的不明白为什么我的变量是一个未定义的集合.

你能帮帮我吗?

以下是我的HTML:

代码语言:javascript
复制
<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>

我的组件JS:

代码语言:javascript
复制
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;
        }
    }
})

我的主计长JS:

代码语言:javascript
复制
angular.module('riskApp').controller('mapController', function 
CountCtrl($scope) {
    this.lastClickedCountry = "test";
    this.countriesUnits = {}
})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-23 12:16:10

属性绑定需要在烤肉串盒中

代码语言:javascript
复制
<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>

有关详细信息,请参阅

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59454184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档