在angularjs内定义两个控制器并使用pug调用数据

时间:2018-09-12 22:23:21

标签: angularjs pug

我想在1个js文件中定义2个控制器(读取2个json)。并使用pug文件从2 json回调数据。我的代码如下:

angular.module('shop-menu.controller', []).controller("Shop-menuController", _shopmenuController)

function _shopmenuController($scope, $http) {
    $http({
        method: 'GET', // POST, PUT, DELETE
        url: '../db/shop-menu.json',
    }).then(function (response) {
        $scope.data = eval(response.data.data);
    }, function (error) {
        console.log('error 003 - Shop: ' + error);
    });
    // $scope.loadlist = function(){
    //  console.log("1")
    // }
}
function _shopController($scope, $http) {
    $http({
        method: 'GET', // POST, PUT, DELETE
        url: '../db/shop-list.json',
    }).then(function (response) {
        $scope.data = eval(response.data.data);
    }, function (error) {
        console.log('error 003 - Shop: ' + error);
    });
}

pug文件:

.row(ng-controller="_shopmenuController")
    ul.list-inline(ng-repeat="phuong in data") 
    li(ng-click="loadlist")
            a.nav-link {{phuong.name}}
.row(ng-controller="_shopController")
    ul.list-inline(ng-repeat="tam in data") 
    li(ng-click="loadlist")
            a.nav-link {{tam.name}}

请帮助我! 谢谢

0 个答案:

没有答案