Javascript 在angular ui中未调用控制器
我在我的控制器中调用rest服务以获取诸如名字和姓氏等值,但它不返回任何值 这是我的控制器:Javascript 在angular ui中未调用控制器,javascript,angularjs,Javascript,Angularjs,我在我的控制器中调用rest服务以获取诸如名字和姓氏等值,但它不返回任何值 这是我的控制器: myApp.controller('profileController', function ($scope, $http) { var url = 'rs/FetchProfile'; $http.get(url).success(function (response) { $scope.profiles = response; console
myApp.controller('profileController', function ($scope, $http) {
var url = 'rs/FetchProfile';
$http.get(url).success(function (response)
{
$scope.profiles = response;
console.log($scope.profiles); //prints nothing
}).error(function (response)
{
console.log("error", response);
});
});
控制器未返回任何值。下面是html代码,其中ng controller=“profileController”
在LoggedIn.hmtl
<div ng-controller="profileController" >
<div ng-repeat="x in profiles" class="col-lg-4 reduce-left-margin-80">
<ul style="list-style-type: none;">
<li>First name and Last name</li>
<li>position xxxxxxx xxxxxxx</li>
<li>Company xxxxxx xxx xxxxx</li>
<li><i class="fa fa-envelope"></i> Email address</li>
</ul>
</div>
</div>
我是否也必须定义第二个状态才能调用我的配置文件控制器 您的路由器配置中有一个输入错误。它应该是
templateUrl
,而不是templateUrl
$stateProvider
.state('profile', {
url: "/profile",
views: {
header: header,
content: {
templateUrl: 'views/LoggedIn.html',
controller: 'profileController'
},
footer: footer
}
})
});
在$stateProvider中,您没有定义它对应于'profileController',您正在使用
controller:function($scope){}
创建一个新的控制器。您是否尝试通过其他工具进行rest api调用?您必须将“controller;function($scope){}”替换为“controller:'profileController'”@Pierreemanuellallemant仍然是一样的。@HamletHakobyan是的,我尝试了postman(chrome rest插件)和它在GET请求时返回的值,但它没有在我的应用程序中返回任何东西
$stateProvider
.state('first', {
url: "/first",
views: {
header: header,
content: {
templateUrl: 'views/HomePage.html',
controller: function ($scope) {
}
},
footer: footer
}
})
.state('LoggedIn', {
url: "/LoggedIn",
views: {
'header': header,
'content': {
temlateUrl: 'views/LoggedIn.html',
controller: function () {
}
},
'footer': footer
}
});
});
$stateProvider
.state('profile', {
url: "/profile",
views: {
header: header,
content: {
templateUrl: 'views/LoggedIn.html',
controller: 'profileController'
},
footer: footer
}
})
});