Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在具有动态输出的angular js中添加链接_Javascript_Jquery_Angularjs_Controller_Directive - Fatal编程技术网

Javascript 如何在具有动态输出的angular js中添加链接

Javascript 如何在具有动态输出的angular js中添加链接,javascript,jquery,angularjs,controller,directive,Javascript,Jquery,Angularjs,Controller,Directive,我在这里有页面说类别,我正在从api请求加载类别 单击第一个类别,我需要加载一些其他页面,比如说产品,并需要从其他一些api加载产品。 当我用simple href链接它时,它会显示出来 {{product.productname}} MyController页面: var app = angular.module('myApp', []); app.controller('CategoryController', function($scope, $http) { $http.

我在这里有页面说类别,我正在从api请求加载类别 单击第一个类别,我需要加载一些其他页面,比如说产品,并需要从其他一些api加载产品。 当我用simple href链接它时,它会显示出来

{{product.productname}}

MyController页面:

    var app = angular.module('myApp', []);
app.controller('CategoryController', function($scope, $http) {
    $http.get("http://192.168.1.112/estore/api/get-categories")
    .success(function(response) {$scope.categories = response.categories;});
});
app.controller('ProductController', function($scope, $http) {
    $scope.id = 2; 
    $http.get("http://192.168.1.112/estore/api/get-products?id=id")
    .success(function(response) {$scope.products = response.categories;});
});
我的索引页:

<body ng-app="myApp">
        <div role="main" class="ui-content" ng-controller="CategoryController">
            <ul class="cat" ng-repeat="x in categories">
            <li>
                <a href="list.html/{{x.id }}"> {{ x.name }} </a>
            </li>
            </ul>  
        </div>
        </body>

我的列表页:

<body ng-app="myApp">
        <div role="main" class="ui-content" ng-controller="ProductController">
            <ul class="cat" ng-repeat="pdts in products">
            <li>
                {{ pdts.productname }}
            </li>
            </ul>  
        </div>
        </body> 

  • {{pdts.productname}

有两个选项:-

1) you can use $state.go() and pass id parameters to products state.

2) you can use $cookiestore and set the id in the cookie and later retrieve in the products state.



var app = angular.module('myApp', []);

   app.config(['$stateProvider',function($stateProvider){
        $stateProvider.state('products',{
           url: '/products/:ID',
           title: 'productlist',
           templateUrl: 'app/views/product/productlist.html',
           controller:'productlistController'
        })
   }]);



app.controller('CategoryController', function($scope, $http ,$state) {

        $http.get("http://192.168.1.112/estore/api/get-categories")
        .success(function(response){
            $scope.categories = response.categories;
        });

        $scope.redirectTo = function(id){
           $state.go('products', {ID : id});
        };

   });



app.controller('ProductController', function($scope, $http , $state) {
        var id = $state.params.ID;
        $http.get("http://192.168.1.112/estore/api/get-products?id="+id)
        .success(function(response) {
            $scope.products = response.products;
        });
   });
索引页

<body ng-app="myApp">
<div role="main" class="ui-content" ng-controller="CategoryController">
     <ul class="cat" ng-repeat="x in categories">
     <li>
          <a ng-click="redirectTo(x.id)"> {{ x.name }} </a>
     </li>
     </ul>  
</div>
</body>

  • {{x.name}

有两个选项:-

1) you can use $state.go() and pass id parameters to products state.

2) you can use $cookiestore and set the id in the cookie and later retrieve in the products state.



var app = angular.module('myApp', []);

   app.config(['$stateProvider',function($stateProvider){
        $stateProvider.state('products',{
           url: '/products/:ID',
           title: 'productlist',
           templateUrl: 'app/views/product/productlist.html',
           controller:'productlistController'
        })
   }]);



app.controller('CategoryController', function($scope, $http ,$state) {

        $http.get("http://192.168.1.112/estore/api/get-categories")
        .success(function(response){
            $scope.categories = response.categories;
        });

        $scope.redirectTo = function(id){
           $state.go('products', {ID : id});
        };

   });



app.controller('ProductController', function($scope, $http , $state) {
        var id = $state.params.ID;
        $http.get("http://192.168.1.112/estore/api/get-products?id="+id)
        .success(function(response) {
            $scope.products = response.products;
        });
   });
索引页

<body ng-app="myApp">
<div role="main" class="ui-content" ng-controller="CategoryController">
     <ul class="cat" ng-repeat="x in categories">
     <li>
          <a ng-click="redirectTo(x.id)"> {{ x.name }} </a>
     </li>
     </ul>  
</div>
</body>

  • {{x.name}

**MyController页面:**`var-app=angular.module('myApp',[]);app.controller('CategoryController',function($scope,$http){$http.get(“).success(function(response){$scope.categories=response.categories;});});app.controller('ProductController',function($scope,$http){$scope.id=2;$http.get(“).success(function(response){$scope.products=response.categories;});})`我建议你彻底地学习一下,以获得对角度如何工作的基本理解。例如,您不应该有两个带有
ng app
指令的
标记。这不是应该是这样的:
$http.get(“http://192.168.1.112/estore/api/get-products?id=“+id)
并坦率地说同意muenchdo.*MyController页面:*`var-app=angular.module('myApp',[]);app.controller('CategoryController',function($scope,$http){$http.get(“).success(function(response){$scope.categories=response.categories;});});app.controller('ProductController',function($scope,$http){$scope.id=2;$http.get(“).success(function(response){$scope.products=response.categories;});})`我建议你彻底地学习一下,以获得对角度如何工作的基本理解。例如,您不应该有两个带有
ng app
指令的
标记。这不是应该是这样的:
$http.get(“http://192.168.1.112/estore/api/get-products?id=“+id)
,坦率地说,同意muenchdo的观点。