Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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/0/drupal/3.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 父指令和子指令的动态模板URL,不起作用_Javascript_Angularjs_Angularjs Directive_Angular Template - Fatal编程技术网

Javascript 父指令和子指令的动态模板URL,不起作用

Javascript 父指令和子指令的动态模板URL,不起作用,javascript,angularjs,angularjs-directive,angular-template,Javascript,Angularjs,Angularjs Directive,Angular Template,我有这个结构 <aspect aspect="aspect" aspectid="props.getId(aspect)"> <simpleproperty property="property"></simpleproperty> <uriproperty property="property"></uriproperty> </aspe

我有这个结构

         <aspect aspect="aspect" aspectid="props.getId(aspect)">
             <simpleproperty property="property"></simpleproperty>
              <uriproperty property="property"></uriproperty>
          </aspect>
也以类似的方式定义了子指令

   .directive("simpleproperty",["$compile","$http",function ($compile,$http) {

    return {
        restrict: "E",
        transclude:true,
        scope:{
            aspect:"="
        },
       link: function (scope, element, attr) {
            scope.props=Props;
           var templateUrl = //if(scope.isURL) "one.html" else "two.html" 
            if(!_.isUndefined(templateUrl)){
                $http.get(templateUrl, {cache: $templateCache})
                    .success(function (html) {
                    element.replaceWith($compile(html)(scope));

                });
            }
        }
    };
}]);
我的要求是使用scope对象,基于一些业务逻辑基本上加载父级和子级的指令模板。但它根本不起作用。我在Stack overflow中读到无法使用templateUrl动态加载模板,这就是我删除它并使用$compile的原因

注意:若我只在children指令中保持模板的动态加载,那个么它可以正常工作,但反之亦然,或者两者都不起作用


请帮忙

这是因为在父级中,您将用新标记替换内容,而子级将被覆盖!当您删除动态加载父项时,子项就存在了,并且可以替换它自己。我理解,但我保留了与父项和子项相关的模板html文件。。。
   .directive("simpleproperty",["$compile","$http",function ($compile,$http) {

    return {
        restrict: "E",
        transclude:true,
        scope:{
            aspect:"="
        },
       link: function (scope, element, attr) {
            scope.props=Props;
           var templateUrl = //if(scope.isURL) "one.html" else "two.html" 
            if(!_.isUndefined(templateUrl)){
                $http.get(templateUrl, {cache: $templateCache})
                    .success(function (html) {
                    element.replaceWith($compile(html)(scope));

                });
            }
        }
    };
}]);