如何在页面加载上设置功能条件?

时间:2016-05-15 17:01:57

标签: javascript angularjs

我有这个控制器:

   (function () {
    "use strict";
    angular.module('damageEvent').controller("inspectionsDamageEventsController", ["siteId",                                                                         "mapguideService",
                                                                                    inspectionsDamageEventsController]);

    function inspectionsDamageEventsController(siteId, mapguideService, inspectionsDamageList) 
    {
       var self = this;
       this.siteId = siteId;
       this.mapguideService = mapguideService;
       this.isMapGuideEnabled = mapguideService.enabled;

       self.mapguideService.zoom("site", self.siteId);

    }
    })();

此行在页面加载时触发:

 self.mapguideService.zoom("site", self.siteId);

我需要根据此值在页面加载时触发上面的行:

this.isMapGuideEnabled

如果isMapGuideEnabled为真,则mapguideService.zoom()会被触发,否则不会。

如何在页面加载时设置此条件?

1 个答案:

答案 0 :(得分:0)

if救援......

(function () {
    "use strict";
    angular.module('damageEvent').controller("inspectionsDamageEventsController", ["siteId",                                                                         "mapguideService",
                                                                                    inspectionsDamageEventsController]);

    function inspectionsDamageEventsController(siteId, mapguideService, inspectionsDamageList) 
    {
       var self = this;
       this.siteId = siteId;
       this.mapguideService = mapguideService;
       this.isMapGuideEnabled = mapguideService.enabled;

       if (this.isMapGuideEnabled) {
         self.mapguideService.zoom("site", self.siteId);
       }
    }
    })();