显然,我在之前的解释中并不清楚,所以我们走了:
function HomeController ($scope, Principal, LoginService, NewtagService, LoginfailService, $state, $http) {
...
$scope.contacts = [{name: 'Peter'}];
...
}
<div ng-controller="HomeController">{{contacts[0].name}}</div>
这会打印'Peter',而
function HomeController ($scope, Principal, LoginService, NewtagService, LoginfailService, $state, $http) {
// $scope.contacts = [{name: 'Peter'}];
function createServiceTag () {
$http({
method: 'POST',
url: '/api/important'
}).then(function successCallback(response) {
$scope.contacts = [
{name:'Lois'}
];
ImportantService.open(response.data);
}, function errorCallback(response) {
console.log(response);
});
}
}
<div ng-controller="HomeController">{{contacts[0].name}}</div>
什么都不打印
答案 0 :(得分:1)
function makeImportantRequest () {
$http({
method: 'POST',
url: '/api/important'
}).then(function successCallback(response) {
$scope.contacts = [
{name:'Luise'}
];
ImportantModalService.open();
}, function errorCallback(response) {
});
}
答案 1 :(得分:1)
在没有$(function(){})
的情况下尝试 $http({
method: 'POST',
url: '/api/important'
}).then(function successCallback(response) {
$scope.contacts = [
{name:'Luise'}
];
ImportantModalService.open();
}, function errorCallback(response) {
});