Angular不选择$ scope.variable_name

埃拉·布瓦(Ela Buwa)

下面是我的HTML代码。

<div class="container" ng-app="mintcart">
    <div class="panel panel-default" ng-controller="categoriesctrl">
    <input type="hidden" ng-model="session.sid" value="<?php echo session_id();?>"/>
        <div class="panel-body">
            <div class="row">
                <ul class="nav nav-pills">
                    <?php
                    $i = 0;
                    while($i < count($list)){
                        $name = $list[$i]['categoryName'];
                        $id = $list[$i]['id'];
                        $normalUrl = $list[$i]['normalImageUrl'];
                        $hoverUrl = $list[$i]['hoverImageUrl'];
                        if($i == 0){
                            echo "<li role='presentation' class='active' ng-click='loadproducts($id)'><a href='#' >$name</a></li>";
                        } else {
                            echo "<li role='presentation' ng-click='loadproducts($id)'><a href='#''>$name</a></li>";
                        }
                        $i++;
                    }
                    ?>
                </ul>
            </div>
      </div>
   </div>
</div>

以下是我的JS代码。

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

app.controller('categoriesctrl', function($scope, $http){
    var auth = {};
    $http({
      method: 'GET',
      url: baseurl + 'api/get_product_categories'
    }).then(function successCallback(response) {
        $scope.categories = response.data.categories;
        // this callback will be called asynchronously
        // when the response is available
    }, function errorCallback(response) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
    });

    $scope.loadproducts = function(item_id) {
        alert($scope.session.sid);
        $http({
          method: 'GET',
          url: baseurl + 'api/get_items_in_category_cart/' + item_id
        }).then(function successCallback(response) {
            $scope.items = response.data.products;
            // this callback will be called asynchronously
            // when the response is available
        }, function errorCallback(response) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        });
        //$scope.Language = lang;
    }; 

});

当loadproducts函数被调用时,alert($ scope.session.sid); 给我“未定义”。我不明白为什么我的元素没有被拾起。任何帮助是极大的赞赏。

萨耶塔兰(Sajeetharan)

php在服务器端工作,您需要使用javascript而不是在视图上设置变量。

在JavaScript中创建一个变量,该变量获取PHP的返回内容。

var sessionid = <?php echo session_id();?>

然后,您可以访问控制器中的变量,

 var app = angular.module("MyApp", []);

app.controller("categoriesctrl", function($scope) {
  $scope.session.sid = sessionid ;
  console.log($scope.session.sid);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Python:避免<<打印“ variable_name =“,variable_name >>”的方法?

来自分类Dev

java lambdaj'variable_name'无法解析为变量错误

来自分类Dev

How to assign class to an element using $scope variable in angular js

来自分类Dev

Angular.js-$ scope.variable不会自动更新

来自分类Dev

Go closure variable scope

来自分类Dev

Java variable scope in if statement

来自分类Dev

Ruby on Rails link_to使用variable_name_path和控制器:variable_name

来自分类Dev

Angular自定义指令-$ scope。$ watch不触发

来自分类Dev

$ scope不返回任何值

来自分类Dev

variable_scope 和 name_scope 之间的实际区别是什么?

来自分类Dev

如何在 Tensorflow 中使用 name_scope 重用/重新打开已经关闭的 variable_scope?

来自分类Dev

Angular:如何从$ http.get方法外部访问angular $ scope.ng-model_name?

来自分类Dev

如何使用.net核心中的。(variable_name)访问类属性?

来自分类Dev

NameError:当我尝试捕获执行时未定义名称“ variable_name”

来自分类Dev

当设置环境变量(例如“ VARIABLE_NAME =”)时,该期间表示什么?

来自分类Dev

main.o:main.c:function main:错误:未定义对'variable_name'的引用

来自分类Dev

仅在一个函数中出现“variable_name”未声明的错误

来自分类Dev

{{ dump( variable_name ) }} 在 opencart-3 中不起作用

来自分类Dev

javascript setInterval()和Variable Scope

来自分类Dev

Tensorflow 中的 tf.variable_scope 和 variable_scope.variable_scope 有什么区别?

来自分类Dev

Angular.js“ Controller as ...” + $ scope。$ on

来自分类Dev

Passing attrs as $scope variables in Angular

来自分类Dev

替代Angular 2.0中的$ scope

来自分类Dev

Angular.js:$ scope与范围

来自分类Dev

在Angular指令中更新$ scope

来自分类Dev

scope of event arguments in angular directive

来自分类Dev

在Angular中从$ scope输出数值

来自分类Dev

Promises, Angular2 and scope

来自分类Dev

Angular.js:$ scope与范围

Related 相关文章

  1. 1

    Python:避免<<打印“ variable_name =“,variable_name >>”的方法?

  2. 2

    java lambdaj'variable_name'无法解析为变量错误

  3. 3

    How to assign class to an element using $scope variable in angular js

  4. 4

    Angular.js-$ scope.variable不会自动更新

  5. 5

    Go closure variable scope

  6. 6

    Java variable scope in if statement

  7. 7

    Ruby on Rails link_to使用variable_name_path和控制器:variable_name

  8. 8

    Angular自定义指令-$ scope。$ watch不触发

  9. 9

    $ scope不返回任何值

  10. 10

    variable_scope 和 name_scope 之间的实际区别是什么?

  11. 11

    如何在 Tensorflow 中使用 name_scope 重用/重新打开已经关闭的 variable_scope?

  12. 12

    Angular:如何从$ http.get方法外部访问angular $ scope.ng-model_name?

  13. 13

    如何使用.net核心中的。(variable_name)访问类属性?

  14. 14

    NameError:当我尝试捕获执行时未定义名称“ variable_name”

  15. 15

    当设置环境变量(例如“ VARIABLE_NAME =”)时,该期间表示什么?

  16. 16

    main.o:main.c:function main:错误:未定义对'variable_name'的引用

  17. 17

    仅在一个函数中出现“variable_name”未声明的错误

  18. 18

    {{ dump( variable_name ) }} 在 opencart-3 中不起作用

  19. 19

    javascript setInterval()和Variable Scope

  20. 20

    Tensorflow 中的 tf.variable_scope 和 variable_scope.variable_scope 有什么区别?

  21. 21

    Angular.js“ Controller as ...” + $ scope。$ on

  22. 22

    Passing attrs as $scope variables in Angular

  23. 23

    替代Angular 2.0中的$ scope

  24. 24

    Angular.js:$ scope与范围

  25. 25

    在Angular指令中更新$ scope

  26. 26

    scope of event arguments in angular directive

  27. 27

    在Angular中从$ scope输出数值

  28. 28

    Promises, Angular2 and scope

  29. 29

    Angular.js:$ scope与范围

热门标签

归档