使用我认为的基本路线,但它不喜欢我。
.config([
'$routeProvider',
function($routerProvider){
$routerProvider
.when('/view',{
templateUrl: 'view-profile.html',
controller: 'UserProfileController'
})
.when('/edit',{
templateUrl: 'edit-profile.html',
controller: 'UserProfileController'
})
.otherwise({
redirectTo: '/view'
});
}
]);
以上工作,我可以在浏览器中手动输入 /view 或 /edit ,它会加载并工作。
我的页面上有用于切换 UI 的按钮,当我这样做时,我会看到新视图,然后它会立即切换回来。我在 /view 上,我单击更改编辑路径,然后进入编辑然后返回查看。但是,当我开始编辑并单击以更改查看时,它会粘住。然后我可以回去好好编辑。它似乎是在页面加载时。
这是我改变观点的方式
this.viewProfile = function () {
$location.path('/view');
};
this.editProfile = function () {
$location.path('/edit');
};
按钮看起来像
开/查看
<button ng-click="user.editProfile()">Edit My Profile</button>
开启/编辑
<button ng-click="user.viewProfile()">Save</button>
谢谢!