এটি আগে জিজ্ঞাসা করা হয়েছিল, এবং উত্তরগুলি থেকে এটি ভাল দেখাচ্ছে না। আমি এই নমুনা কোডটি বিবেচনায় রেখে জিজ্ঞাসা করতে চাই ...
আমার অ্যাপ্লিকেশনটি সরবরাহ করে এমন পরিষেবাতে বর্তমান আইটেমটি লোড করে। এমন বেশ কয়েকটি নিয়ন্ত্রণকারী রয়েছে যা আইটেমটি পুনরায় লোড না করে আইটেমের ডেটা ম্যানিপুলেট করে।
আমার কন্ট্রোলাররা আইটেমটি এখনও সেট না করা থাকলে এটি পুনরায় লোড করবে, অন্যথায়, এটি পরিষেবা থেকে বর্তমানে লোড হওয়া আইটেমটি নিয়ন্ত্রণকারীদের মধ্যে ব্যবহার করবে।
সমস্যা : আমি আইটেম এইচটিএমএল লোড না করে প্রতিটি নিয়ামকের জন্য পৃথক পাথ ব্যবহার করতে চাই।
1) এটা সম্ভব?
২) যদি এটি সম্ভব না হয় তবে আমি এখানে যা এসেছি তার চেয়ে নিয়ামক প্রতি পাথের চেয়ে আরও ভাল উপায় থাকতে পারে?
app.js
var 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 linked
function 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);
}
রেজোলিউশন।
স্থিতি : গৃহীত উত্তরে প্রস্তাবিত অনুসারে অনুসন্ধান কোয়েরিটি ব্যবহার করে আমাকে প্রধান নিয়ামককে পুনরায় লোড না করে বিভিন্ন ইউআরএল সরবরাহ করার অনুমতি দেয়।
app.js
var app = angular.module('myModule', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/items', {templateUrl: 'partials/items.html', controller: ItemsCtrl}).
when('/item/:itemId/', {templateUrl: 'partials/item.html', controller: ItemCtrl, reloadOnSearch: false}).
otherwise({redirectTo: '/items'});
}]);
Item.html
<!-- Menu -->
<dd id="fooTab" item-tab="view.name" ng-click="view = views.foo;"><a href="#/item/{{item.id}}/?view=foo">Foo</a></dd>
<dd id="barTab" item-tab="view.name" ng-click="view = views.bar;"><a href="#/item/{{item.id}}/?view=foo">Bar</a></dd>
<!-- Content -->
<div class="content" ng-include="" src="view.template"></div>
controller.js
function ItemCtrl($scope, $routeParams, Appts) {
$scope.views = {
foo: {name: 'foo', template: 'partials/itemFoo.html'},
bar: {name: 'bar', template: 'partials/itemBar.html'},
}
$scope.view = $scope.views[$routeParams.view];
}
directives.js
app.directive('itemTab', function(){
return function(scope, elem, attrs) {
scope.$watch(attrs.itemTab, function(val) {
if (val+'Tab' == attrs.id) {
elem.addClass('active');
} else {
elem.removeClass('active');
}
});
}
});
আমার পার্টিশালের ভিতরে থাকা সামগ্রীটি মোড়ানো রয়েছে ng-controller=...