Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
AngularJS指令获取的模板URL不工作_Angularjs - Fatal编程技术网

AngularJS指令获取的模板URL不工作

AngularJS指令获取的模板URL不工作,angularjs,Angularjs,我对使用AngularJS1完全是初学者 我现在所做的是使用以下代码创建我自己的自定义指令: var ui = angular.module('ui',[ 'core' ]); ui.directive( 'shTag', function(){ return { restrict: 'E', scope: { text: '=', }, link: function(scope, element,

我对使用AngularJS1完全是初学者

我现在所做的是使用以下代码创建我自己的自定义指令:

var ui = angular.module('ui',[ 'core' ]);

ui.directive( 'shTag', function(){
    return {
        restrict: 'E',
        scope: {
            text: '=',
        },
        link: function(scope, element, attrs){
            scope.type = attrs.type;
        },
        templateUrl: config.base_url + "/directive/tag",
    }
});
正如您所看到的,templateUrl是在我的后端中获取的,它只是返回html作为响应

这是对请求的响应:

<span class="" > [[ scope.text ]]</span>
[[scope.text]]
但是,当它没有显示scope.text值时

注意,我使用[[]]作为插值器

任何帮助都将不胜感激


谢谢。

请确保在获取模板之前正确配置插值。(在引导过程中,在应用程序的其余部分运行之前!)
由于您刚刚开始,我建议您在熟悉概念和调试问题之前坚持使用默认设置。

假设您的$interpolateProvider配置正确,可以使
[[]]
正常工作,请使用Alainlb提到的
[[text]]
,并确保在标记用法上设置了属性值“text”,如下所示:

<sh-tag text="'display me to the world'"></sh-tag>

因为您使用的是隔离作用域,
text
将具有值的唯一方法是为该属性指定值。注意,我在这里使用了一个字符串,但它可能是父作用域上的一个变量

我还建议您在inspector中检查您的网络,以确保templateUrl的请求正在通过(url是100%正确的)


除此之外,一切看起来都很好

由于您没有使用
controllerAs:'scope'
语法,因此不必使用
scope.text
,只需使用
[[text]]

$scope上的所有内容都可以在指令中找到


(另外:看看angular 1.5中的组件,它们添加了一些语法糖,使用起来非常性感)

使用[[text]]instead我不熟悉“interpolator”,但是在视图中显示范围数据的基本方法是
{{text}