当我致电{{Store.Product.Name}} {{Store.Product.Price}} {{Store.Product.Description}}时 [英] When I Call {{Store.Product.Name}} {{Store.Product.Price}} {{Store.Product.Description}}

查看:93
本文介绍了当我致电{{Store.Product.Name}} {{Store.Product.Price}} {{Store.Product.Description}}时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我拨打{{store.product.name}} {{store.product.price}} {{store.product.description}}时,我打电话时,它不显示但没有错误。





<!Doctype html>

< html>



< head>

< title> Gem store< / title>



< link rel =stylesheet type =text / csshref =css / bootstrap.css>



< / head>



< body>

<! - 指令controlerName别名 - >



{{store.product.name} }



$ {{store.product.price}}



{{store.product.description}}







< / body>

< script type = text / javascriptsrc =js / angular.js>< / script>

< script type =text / javascriptsrc =js / app.js> < / script>

< / html>





(function(){

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



app.controller('StoreController',function(){

this.product = gem;

});



var gem = {

名称:'Dodecahedron',

价格:2.95,

描述:'你',

}



})();

解决方案

{{store.product.price}}

{{store.product.description}}







< / body>

< script type =text / javascriptsrc =js / angular.js>< / script>

< script type =text / javascript src =js / app.js>< / script>

< / html>





(function(){

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



app。 controller('StoreController',function(){

this.product = gem;

});



var gem = {

名称:'Dodecahedron',

价格:2.95,

描述:'你的',

}



})();


我不太了解角度,虽然我知道它是纠正绑定会在没有错误的情况下失败。



但我能从你的代码中看到的是这个问题可能是由吊装造成的。

你在app.contro之后声明gem勒勒电话。如果在函数中间声明变量,则将悬挂到函数作用域bij javascript的顶部。



但它们将是未定义直到声明!



尝试将gem声明在anonymouse函数的顶部;



 function ( ){
var app = angular.module(' store',[]),
gem = {
name:' 十二面体'
价格: 2 95
说明:' 您的'
};

app。 controller(' StoreController' function ( ){
this .product = gem;
});


})();





再说一次,我不喜欢Angular的流程(我自己就是淘汰赛的人);但是在功能范围顶部宣称你是变量最好的做法无论如何


when i call when i call {{store.product.name}} {{store.product.price}} {{store.product.description}}, it not display but dont have an error.


<!Doctype html>
<html>

<head>
<title>Gem store</title>

<link rel="stylesheet" type="text/css" href="css/bootstrap.css">

</head>

<body>
<!-- directives controlerName alias -->


{{store.product.name}}


$ {{store.product.price}}


{{store.product.description}}




</body>
<script type="text/javascript" src="js/angular.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</html>


(function(){
var app = angular.module('store', [ ]);

app.controller('StoreController', function(){
this.product = gem;
});

var gem = {
name: 'Dodecahedron',
price: 2.95,
description: 'Your ',
}

})();

解决方案

{{store.product.price}}

{{store.product.description}}




</body>
<script type="text/javascript" src="js/angular.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</html>


(function(){
var app = angular.module('store', [ ]);

app.controller('StoreController', function(){
this.product = gem;
});

var gem = {
name: 'Dodecahedron',
price: 2.95,
description: 'Your ',
}

})();


I don't know angular very well, although I know it is correct that the binding will fail without an error.

But what I can see from you're code is that this problem might be caused by hoisting.
You declare "gem" after the app.controller call. If you declare variables midway a function the will be 'hoisted' to the top of the function scope bij javascript.

But they will be "undefined" untill the declaration!

Try putting the declaration of "gem" at the top of the anonymouse function;

(function(){
var app = angular.module('store', [ ]),
    gem = {
        name: 'Dodecahedron',
        price: 2.95,
        description: 'Your ',
    };

app.controller('StoreController', function(){
    this.product = gem;
});


})();



Again I'm not familiair with the flow of Angular (I'm a knockout guy myself;), but declaring you're variables at the top the function scope is best practise anyway.


这篇关于当我致电{{Store.Product.Name}} {{Store.Product.Price}} {{Store.Product.Description}}时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发语言最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆