각도가 처음입니다 - 내 문제 - $scope.editProfile()
으로 전화하면 panels.left
의 값이 변경되지만 페이지의 내용은 변경되지 않습니다. html 파일에서 다음과 같이 ng-include를 사용하고 있습니다.ng-include가 변경 될 때 렌더링 업데이트
<div ng-include src="leftPanel"></div>
페이지 뷰를로드하면/profile.html이 div에 렌더링됩니다. 하지만 나중에 $scope.editProfile()
라고 부르면 div가 뷰/edit.html의 내용으로 새로 고쳐지기를 원합니다. 값은 공장에서 변경되지만 (console.log에서 확인 됨) 페이지 내용은 업데이트되지 않습니다.
myApp.factory("panels", function() {
return {
left: "views/profile.html",
center: "views/msgs.html",
right: "views/friends.html"
};
});
myApp.controller("homeCtrl", function ($scope, api, panels) {
$scope.leftPanel = panels.left;
$scope.centerPanel = panels.center;
$scope.rightPanel = panels.right;
});
myApp.controller("profileCtrl", function ($scope, api, panels) {
$scope.user = api.bio.get();
$scope.editProfile = function() {
panels.left = "views/edit.html";
};
});
당신은로드 뷰에 대한 angulars 경로 또는 상태를 사용해야합니다. https://docs.angularjs.org/api/ngRoute/service/$route – phylax
내 페이지의 뷰가 모두 div로 감싸여 있으며 세 개의 다른 뷰가 항상 페이지에 있습니다. 내 이해는 각도 라우트 및 ng- 보기는 한 번에 하나의보기 만 처리 할 수 있습니다. – lwalden