指令書を書いています。
これは私が使用しているコードです:
angular.module('weather', []).directive('myWeather', [
'$ionicSideMenuDelegate', function($ionicSideMenuDelegate) {
var createWeatherConditionLabel, linkFunction;
createWeatherConditionLabel = function(type) {
var label;
label = '';
debugger;
switch (type) {
case 0:
label = 'Clear';
break;
case 1:
label = 'Clear';
break;
case 2:
label = 'Light Cloud';
break;
case 3:
label = 'Light Cloud';
break;
case 5:
label = 'Windy';
break;
case 6:
label = 'Foggy';
break;
case 7:
label = 'Cloudy';
break;
case 15:
label = 'Rain';
break;
case 18:
label = 'Sleet';
break;
case 21:
label = 'Hail';
break;
case 27:
label = 'Snow';
break;
case 30:
label = 'Showers';
}
return label;
};
linkFunction = function(scope, el, attr) {
console.log("scope:", scope);
scope.showWeatherDetails = false;
scope.evtClickExpandMenuWeather = function() {
if (scope.showWeatherDetails === false) {
return scope.showWeatherDetails = true;
} else {
return scope.showWeatherDetails = false;
}
};
scope.$watch((function() {
return $ionicSideMenuDelegate.isOpenRight();
}), function(isOpen) {
if (!isOpen) {
return scope.showWeatherDetails = false;
}
});
return scope.weatherLabel = createWeatherConditionLabel(scope.weatherType);
};
return {
restrict: 'E',
replace: true,
templateUrl: './directives/tpl.html',
scope: {
weatherData: "=",
weatherType: "="
},
link: linkFunction
};
}
]);
ディレクティブは次のように呼び出されます。
<my-weather weather-data="zones[0].weatherData" weather-type="zones[0].weatherData.weather_type"></my-weather>
これを作成してディレクティブ テンプレートで使用するには、関数を呼び出す必要がありますweatherLabel
が、scope.weatherType が定義されていないためできません。
リンク関数を呼び出す前にスコープが定義されるのを待つにはどうすればよいですか?
または、これを行うためのより効率的で効率的な (パフォーマンスに関する) 方法はありますか? 助けてくれてどうもありがとう