简体   繁体   English

布尔值未在Angular中传递

[英]Boolean value not being passed in Angular

I'm trying to do something relatively simple here, pass in the boolean variable multiExpandable down a recursive tree created by my directive. 我正在尝试做相对简单的事情,将布尔变量multiExpandable传入我的指令创建的递归树。 The variable is later evaluated by my service. 稍后由我的服务评估该变量。 In my service it keeps coming back as undefined for whatever reason. 在我的服务中,无论出于何种原因,它都会以未定义的形式返回。

I have no idea why this is doing this to me! 我不知道为什么要这样对我! The application variable takes in string object and does, literally, the same thing and is absolutely fine. 应用程序变量接受字符串对象,并且在字面上做相同的事情,并且绝对可以。 My code is below, note that a lot of it has been trimmed to simply show you what is important. 我的代码在下面,请注意,其中的许多内容已被裁剪以仅向您显示重要内容。 Why is this happening? 为什么会这样呢?

My directive: 我的指令:

.directive("navigation", function() {
          return {
                restrict: 'E',
                replace: true,
                scope: {
                    menu: '=',
                    multiExpandable: '=',
                    application: '=',
                },
                controller: function($scope) {
                    $scope.toggleExpand = NavigationService.toggleExpand;
                },

              ...

            }

my template: 我的模板:

<ul style="list-style: none">
<li ng-repeat="node in menu.Folders">
    {{multiExpandable}}
    <i class="fa" ng-click="toggleExpand(node, application, menu, multiExpandable)"></i>
    <navigation menu="node" application="application" multiExpandable="multiExpandable"    ng-show="node.expanded == true"></navigation>
</li>
</ul>

where the directive is called: 指令被调用的位置:

<navigation class="nav tree" menu="applications[currentApplication].Menu" application="currentApplication" multiExpandable="expandable"></navigation>

And the value in the service (the console log statement is returning it as undefined): 以及服务中的值(控制台日志语句将其作为未定义返回):

_toggleExpand = function (application, multiExpandable) {

                    //some code

                    console.log("in TOGGLE EXPAND - multiExpandable:");
                    console.log(multiExpandable);

                    //some code
 }

Your directive attribute declaration is camelCase and therefore you need a dash in the HTML like this: 您的指令属性声明为camelCase,因此您需要在HTML中使用破折号,如下所示:

multi-Expandable="multiExpandable"

Note that angular: 注意角度:

  • Strip x- and data- from the front of the HTML element/attributes, and 从HTML元素/属性的前面去除x和data-,然后
  • Converts the HTML attributes with : , - , or _ -delimited name to camelCase. 将带有:-_分隔名称的HTML属性转换为camelCase。

You can read more about it here: 你可以在这里读更多关于它的内容:

https://docs.angularjs.org/guide/directive https://docs.angularjs.org/guide/directive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM