第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

您可以在不重新加載AngularJS中的控制器的情況下更改路徑嗎?

您可以在不重新加載AngularJS中的控制器的情況下更改路徑嗎?

揚(yáng)帆大魚 2019-10-15 15:06:55
之前有人問過這個(gè)問題,從答案來看它看起來并不好。我想考慮一下此示例代碼...我的應(yīng)用程序?qū)?dāng)前項(xiàng)目加載到提供它的服務(wù)中。有幾個(gè)控制器可以在不重新加載項(xiàng)目的情況下操縱項(xiàng)目數(shù)據(jù)。如果尚未設(shè)置,我的控制器將重新加載該項(xiàng)目,否則,它將在控制器之間使用該服務(wù)中當(dāng)前加載的項(xiàng)目。問題:我想為每個(gè)控制器使用不同的路徑,而無需重新加載Item.html。1)有可能嗎?2)如果這不可能,那么與我在這里提出的相比,是否有更好的方法為每個(gè)控制器設(shè)置路徑?app.jsvar app = angular.module('myModule', []).  config(['$routeProvider', function($routeProvider) {    $routeProvider.      when('/items', {templateUrl: 'partials/items.html',   controller: ItemsCtrl}).      when('/items/:itemId/foo', {templateUrl: 'partials/item.html', controller: ItemFooCtrl}).      when('/items/:itemId/bar', {templateUrl: 'partials/item.html', controller: ItemBarCtrl}).      otherwise({redirectTo: '/items'});    }]);Item.html<!-- Menu --><a id="fooTab" my-active-directive="view.name" href="#/item/{{item.id}}/foo">Foo</a><a id="barTab" my-active-directive="view.name" href="#/item/{{item.id}}/bar">Bar</a><!-- Content --><div class="content" ng-include="" src="view.template"></div>controller.js// Helper function to load $scope.item if refresh or directly linkedfunction itemCtrlInit($scope, $routeParams, MyService) {  $scope.item = MyService.currentItem;  if (!$scope.item) {    MyService.currentItem = MyService.get({itemId: $routeParams.itemId});    $scope.item = MyService.currentItem;  }}function itemFooCtrl($scope, $routeParams, MyService) {  $scope.view = {name: 'foo', template: 'partials/itemFoo.html'};  itemCtrlInit($scope, $routeParams, MyService);}function itemBarCtrl($scope, $routeParams, MyService) {  $scope.view = {name: 'bar', template: 'partials/itemBar.html'};  itemCtrlInit($scope, $routeParams, MyService);}解析度。狀態(tài):按照接受的答案中的建議使用搜索查詢,這使我可以提供不同的URL,而無需重新加載主控制器。我的局部中的內(nèi)容用 ng-controller=...
查看完整描述

3 回答

?
慕神8447489

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊

為什么不只是將ng-controller提升一級(jí),


<body ng-controller="ProjectController">

    <div ng-view><div>

而且不要在路線中設(shè)置控制器,


.when('/', { templateUrl: "abc.html" })

這個(gè)對我有用。


查看完整回答
反對 回復(fù) 2019-10-15
  • 3 回答
  • 0 關(guān)注
  • 649 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)