【发布时间】:2016-08-25 06:23:10
【问题描述】:
我被困在 ng-view 中调用 json 文本。在普通的 HTML {{profile.experience}} 中,这非常有效。从 json 中获取数据。 但是由于我添加了 ng-view {{profile.experience}} 无法从 json 中获取数据。
<div class="profile-snapshot">
<ul>
<li><span>Experience:</span><p> {{profile.experience}}</p></li>
<li><span>Education:</span><p> {{profile.education}}</p></li>
<li><span>Designation:</span><p>{{profile.designation}}</p></li>
<li><span>Age:</span><p>32</p></li>
<li><span>City:</span><p>Thane</p></li>
</ul>
</div>
这就是我的 json 的样子
{
"experience": "Experience 8 Years asda s",
"education": "MBA, B.COM",
"designation": "UX Designer, Front End Developer"
}
这就是我的 angularjs 代码的样子
var accord = angular.module('accord', []);
var profileLoad = angular.module('profileLoad',[]);
var app2 = angular.module('main-app', ['accord','profileLoad','ngRoute']);
profileLoad.controller('profileCntrl', function($scope, $http){
'use strict';
$http.get('candidateProfile.json').success(function(data) {
$scope.profile = data;
});
});
app2.config(function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'profile.html',
controller: 'StudentController'
})
.when('/viewStudents', {
templateUrl: 'profile-edit.html',
controller: 'StudentController'
})
.otherwise({
redirectTo: '/home'
});
});
谁能帮我在 ng-view 中获取 json 数据?
【问题讨论】:
-
尝试告诉 Angular 您在
success块内使用$scope.$apply()更新了数据。 -
您能详细说明一下吗?如果可以的话
-
$scope.apply()告诉 Angular 发生了模型更新,它需要更新绑定到该范围的视图。更新$scope.profile后,尝试在success函数中调用$scope.$apply() -
感谢@MuliYulzary 尝试过。但没有运气。认为我应该上传plnkr.co
-
去吧,我去看看。
标签: angularjs angularjs-routing ng-view