我仍然是Angularjs的新程序员,我在向我的网站添加控制器时遇到了问题。我有两个其他控制器连接到网站,工作正常,但由于某种原因这个没有被识别。
我的app.js
var app = angular.module('app', ['JobCtrl','JobSvc','WebsiteCtrl', 'WebsiteSvc','ClientCtrl','ClientSvc','ui.bootstrap', 'ui.bootstrap.tpls']);
我的HTML
<!DOCTYPE html>
<div ng-app="app">
<div ng-controller="ClientCtrl" ng-cloak>
<div class="row">
<br />
<div class="col-sm-2 pull-right">
<button class="btn btn-primary" ng-click="showModal('Add')">Add Client</button>
</div>
<input ng-model="searchKeyword" type="text" class="form-control col-md-6 pull-right" placeholder="Search Clients...">
<h2 class="col-md-4">Clients</h2>
</div>
<table class="table table-condensed table-hover">
<thead>
<td class="text-center">
<strong>Name</strong>
</td>
<td class="text-center">
<strong>Actions</strong>
</td>
</thead>
<tbody ng-repeat="c in model.clientList | filter: searchKeyword ">
<tr>
<td class="text-center">
{{c.Name}}
</td>
<td class="text-center">
<button class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Edit" ng-click="selectClient(c); showModal('Edit', c)" /><span class="glyphicon glyphicon-pencil"></span>
<button class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Delete" ng-click="selectClient(c); showModal('Delete', c)" /><span class="glyphicon glyphicon-trash"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
我的控制器
angular.module('app')
.controller('ClientCtrl', ['ClientService', '$scope', '$http', '$uibModal', function (ClientService, $scope, $http, $uibModal, $uibModalInstance) {
//$scope.model = ClientService.getClients();
$scope.new = {
Client: {}
};
//create alerts when page reloads after crud functions
if (localStorage.getItem("Success")) {
$scope.alert = "Success";
$scope.alertMessage = localStorage.getItem("Success");
localStorage.clear();
} else if (localStorage.getItem("Error") && localStorage.getItem("Error") != null) {
//sometimes get errors even when adding, deleting, updating is successful
$scope.alert = "Error";
$scope.alertMessage = localStorage.getItem("Error");
localStorage.clear();
};
getClients();
function getClients() {
ClientService.getClients()
.then(
function (data) {
$scope.model = data;
},
function (errResponse) {
console.log("Error while getting clients");
}
);
}
$scope.addClient = function () {
ClientService.addClient()
.then(
function (success) {
localStorage.setItem("Success", "Added client Id:" + success.Id + " Successfully!");
},
function (error) {
localStorage.setItem("Error", "Error while adding client! " + error.status + ":" + error.statusText);
alert(error.status + " " + error.statusText);
}
);
//location.reload();
}
$scope.updateClient = function () {
ClientService.updateClient()
.then(
function (success) {
localStorage.setItem("Success", "Updated client Id:" + success.Id + " Successfully!");
},
function (error) {
localStorage.setItem("Error", "Error while updating client! " + error.status + ":" + error.statusText);
alert(error.status + " " + error.statusText);
}
);
//location.reload();
}
$scope.deleteClient() = function () {
ClientService.deleteClient()
.then(
function (success) {
localStorage.setItem("Success", "Deleted client Id: " + success.Id + " Successfully!");
},
function (error) {
localStorage.setItem("Error", "Error while deleting client: " + error.status + error.statusText);
alert(error.status + " " + error.statusText);
}
);
//location reload();
}
//select client
$scope.selectClient = function (client) {
$scope.selectedClient = client;
}
//show modal function
$scope.showModal = function (action, obj) {
$scope.showBool = true; //boolean to be able to exit modal after update
$scope.model.runButtonText = "Run Job"; //this is for run job only
$scope.$modalInstance = $uibModal.open({
scope: $scope,
inputs: {
title: action + " Client"
},
restrict: "E",
templateUrl: 'app/modal/ClientModals/modal' + action + 'Template.html',
controller: "JobCtrl",
backdrop: 'static',
keyboard: false
});
}
//exit modal function
$scope.exitModal = function () {
$scope.$modalInstance.dismiss('cancel');
};
}]);
任何帮助都会很棒,我只是不明白我的其他控制器是如何被定义的,但这个不是。
答案 0 :(得分:0)
您在控制器创建中忘记了一个依赖项(try {
PackageInfo installedPackageInfo = getPackageManager()
.getPackageInfo(installedPackageName, PackageManager.GET_ACTIVITIES);
long firstInstallTime = installedPackageInfo.firstInstallTime;
long lastUpdateTime = installedPackageInfo.lastUpdateTime;
// installationRequestTime is the time which you request for the PackageInstaller to install your package. This time should be got from System.currentTimeMillis()
return firstInstallTime > installationRequestTime || lastUpdateTime > installationRequestTime;
} catch (PackageManager.NameNotFoundException e) {
// First time installation and user choose to not install the app
return false;
}
):
$uibModalInstance
应该是:
.controller('ClientCtrl', ['ClientService', '$scope', '$http', '$uibModal',
function (ClientService, $scope, $http, $uibModal, $uibModalInstance) {