我知道這是非常微不足道的問題,但我無法理解問題。工廠不在控制器內
myApp.factory("States", ['runajax', function(runajax) {
var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];
return states;
}]);
myApp.controller("TypeaheadCtrl", function($scope, States) {
$scope.selected = undefined;
$scope.states = States;
console.log($scope.states);
});
我檢查控制檯,它顯示未定義。
可能與「runajax」是什麼有關,它與所顯示的不同 – charlietfl
即使沒有runjax服務,它也不起作用。我一直未定義 –
顯示的代碼的工作原理如下所示。按照[mcve]創建演示文稿,再現問題 – charlietfl