Có 2 cách khai báo một
Controller trong Angularjs:
Cách 1:
angular.module("productPageApp").controller("ProductPageController",function($scope){
$scope.isQuickViewMode=4;
});
angular.module("productPageApp").directive("productPage",
function($filter){
var directive = {
restrict: "E",
templateUrl: "product-page.directive.html",
controller: "ProductPageController",
};
return directive;
});
Trong trang product-page.directive.html
<div>
{{ isQuickViewMode }}
</div>
Cách 2:
angular.module("productPageApp").controller("ProductPageController",
ProductPageController);
ProductPageController.$inject = [ "$log",
"$scope", "$filter", "$window"];
function ProductPageController($log, $scope, $filter,
$window) {
var productPageCtrl = this;
productPageCtrl.isQuickViewMode = "1";
}
angular.module("productPageApp").directive("productPage",
function($filter){
var directive = {
restrict: "E",
templateUrl: "product-page.directive.html",
controller: "ProductPageController",
controllerAs: "productPageCtrl",
};
return directive;
});
Trong trang product-page.directive.html
<div>
{{ productPageCtrl.isQuickViewMode
}}
</div>
Không có nhận xét nào:
Đăng nhận xét