第一次問aq,所以如果我做錯了什麼,請讓我知道,所以我可以修復它,因爲我已經嘗試在這裏找到答案,但不能,所以任何和所有幫助將不勝感激。控制器中的功能沒有被擊中
我試圖加載一個「國家」使用控制器的列表,似乎一切順利,沒有錯誤,沒有警告,它加載模塊和命中角度控制器,但它從來沒有命中功能/進入控制器功能內的代碼。我錯過了什麼嗎?難道我做錯了什麼?
Register.cshtml
<div ng-app="RegisterApp" class="form-group" ng-controller="CountriesController as CountriesCtrl">
<label class="input-desc">Country</label>
<select ng-model="country"
ng-options="country.Id as country.Name for country in countries">
<option value="{{CountriesCtrl.country.Id}}">{{CountriesCtrl.country.Name}}</option>
</select>
</div><!-- End .from-group -->
RegisterApp.js
var app = angular.module("RegisterApp", []);
CountriesService.js
/// <reference path="../App.js" />
angular.module("RegisterApp").service("CountriesService", function ($http) {
this.getCountries = function() {
return $http({
method: "Get",
url: "/Account/GetCountries"
});
};
});
CountriesController.js
/// <reference path="../Services/CountriesService.js" />
angular.module("RegisterApp").controller("CountriesController", function ($scope, CountriesService) {
getCountries();
function getCountries() {
CountriesService.getCountries()
.success(function (data, status, headers, config) {
$scope.countries = data;
$scope.country = $scope.countries[0];
})
.error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
}
});
編輯:移動NG-應用,被錯誤地複製這樣的,是我做只是張貼將q之前嘗試一些變化,遺憾的是
嘗試使用'app.service'和'app.controller'而不是'angular.module(「RegisterApp」)。service ...'。如果您缺少'ng-app'指令,請查看Sharikovs的回答 – Arg0n
感謝回覆@ Arg0n,將它改回來使用,因爲它是我最初的樣子,並且更改了ng-app指令,仍然沒有去,它擊中控制器,成功註冊它,但只是跳過內部代碼,沒有錯誤甚至警告。任何其他想法也許......?將不勝感激! – pwjvr
我添加了一個新的答案和一個可用的JSFiddle。 – Arg0n