私は定期的にアドバイスを受ける消費者です。それは非常に貴重なツールです - すべての助けをありがとう!角度メソッドを定義する方法
しかし、これは私の最初の質問です。私はAngularの新機能ですが、ロバの年のサーバーサイドの作業を行っています。
私はサーバーのRESTサービスを呼び出すコントローラ上にメソッドを持っています。私の問題は、コントローラがインスタンス化されるたびにこのメソッドが呼び出されることです。私は関数を宣言する別の方法が必要であることを知っていますが、私は何を検索するのか分かりません。
ここに私のhtmlです:
function Logout($http) {
$http({ url: '/api/UI/Logout', method: 'GET' });
}
:
<html lang="en" data-ng-app="mLS" ng-controller="mLSController">
<head>....</head>
...
<li><a ng-if="userName" ng-click="Logout()">logout</a></li>
、私のモジュール(モジュールDEFは別の場所ですが、それはOKらしい)
var app = angular.module('mLS');
app.controller('mLSController', function ($scope, $http, $window, $location) {
$http({
url: '/api/UI/GetUsername',
method: 'GET'
}).success(function (data, status, headers, config) {
$scope.userName = data;
$scope.desiredPath = $location.path();
if (!$scope.userName && $scope.desiredPath != '/Account/Login')
$window.location.href = '/Account/Login';
});
});
function Logout($http) {
$http({ url: '/api/UI/Logout', method: 'GET' });
}
//app.
// controller('mLSController', function ($scope, $http) {
// $scope.Logout = function() {
// $http({ url: 'api/UI/Logout', method: 'GET' });
// };
// });
//app.
// controller('mLSController', ['$scope', '$http', 'Logout', function ($scope, $http, Logout) {
// $scope.callLogout = function() {
// Logout();
// };
// }]).
// factory('Logout', ['$http', function (protocol) {
// protocol({ url: 'api/UI/Logout', method: 'GET' }).success(function() {
// $scope.Logout = true; });
// }]);
だから私の問題は、その現在のコードです
はまったく呼び出されていません。コントローラーに入れた場合は、Logout()
が呼び出されますコントローラがインスタンス化されます。それは理想的ではない。
助けてください!
問題はありません:) – Bharat