Angularjs 变量在angular JS中的所有公开方式如何

Angularjs 变量在angular JS中的所有公开方式如何,angularjs,Angularjs,我是AngularJS的新手,我以前使用过像Handlebar这样的库作为模板。在Handlebar中,任何从javascript公开的变量都可以在HTML中使用双大括号{{}。我看到大括号在AngularJS中也以类似的方式使用,但这并不是获得如下所示变量的唯一方法 <div class="main" ng-controller="MainController"> <h1>{{ title }}</h1> //Here title is inside

我是AngularJS的新手,我以前使用过像Handlebar这样的库作为模板。在Handlebar中,任何从javascript公开的变量都可以在HTML中使用双大括号{{}。我看到大括号在AngularJS中也以类似的方式使用,但这并不是获得如下所示变量的唯一方法

<div class="main" ng-controller="MainController">
   <h1>{{ title }}</h1> //Here title is inside curly braces like handlebars
   <h2>{{ promo }}</h2>
   <div ng-repeat="product in products" class="col-md-6"> //here products is inside quotations without curly braces
    <img ng-src="{{product.cover}}"> //here product.cover is inside quotations with curly braces.
    <app-info info="move"></app-info> //here move is inside quotations without curly braces. app-info is a directive created in the app. 

{{title}}//这里的title位于像把手一样的花括号内
{{promo}}
//这里的产品是没有花括号的内部报价
//这里的product.cover是带花括号的内部报价。
//这里的移动是没有大括号的内部引用。应用程序信息是在应用程序中创建的指令。
这让我很困惑,我无法轻松地找出在哪里使用{{}}以及在哪里不使用它们。有没有一套基本的规则可以让我更容易做到?任何建议都很好

双大括号(
{}
)表示一个

-数据(没有大括号,只有实际的js数据)或纯文本(在使用双大括号传递之前,可以使用角度分析器进行解析)

当有疑问时,您可以随时检查以查看是否需要传递表达式。例如,它声明必须传递模板(表示表达式)。

双大括号(
{}
)表示

-数据(没有大括号,只有实际的js数据)或纯文本(在使用双大括号传递之前,可以使用角度分析器进行解析)

当有疑问时,您可以随时检查以查看是否需要传递表达式。例如,它声明必须传递模板(表示表达式)。

双大括号(
{}
)表示

-数据(没有大括号,只有实际的js数据)或纯文本(在使用双大括号传递之前,可以使用角度分析器进行解析)

当有疑问时,您可以随时检查以查看是否需要传递表达式。例如,它声明必须传递模板(表示表达式)。

双大括号(
{}
)表示

-数据(没有大括号,只有实际的js数据)或纯文本(在使用双大括号传递之前,可以使用角度分析器进行解析)

当有疑问时,您可以随时检查以查看是否需要传递表达式。例如,它声明您必须传递模板(表示表达式)。

在html中:

<div> This is some regular text your need {{interpretThis}} to say angular that you want to interpret that part </div>

//this is a regular attribute, angular don't know that he should interpret
<div class="{{interpretThis}}"></div>
这是一些常规文本,您需要{{interpretatthis}}来表示您想要解释该部分
//这是一个常规属性,我不知道他应该解释
关于指令:

当您定义一个指令时,您可以添加一个独立的作用域,并从HTML绑定变量

无论何时需要或不使用大括号,都取决于定义

 scope:{
    //Will interpret
    "this": "=",
    //Will interpret as a string
    "that": "@"
 }

 <my-directive this="interpretThis" that="{{interpretThat}}"></my-directive>
范围:{
//将解释
“this”:“=”,
//将解释为字符串
“该”:“@”
}
“that”将包含{{interpretatthat}}的字符串解释,而不是var

请注意,几乎所有的angular内置指令都使用“=”类型。因此,在99%的角度指令中,您不必使用大括号

希望有帮助。

在您的html中:

<div> This is some regular text your need {{interpretThis}} to say angular that you want to interpret that part </div>

//this is a regular attribute, angular don't know that he should interpret
<div class="{{interpretThis}}"></div>
这是一些常规文本,您需要{{interpretatthis}}来表示您想要解释该部分
//这是一个常规属性,我不知道他应该解释
关于指令:

当您定义一个指令时,您可以添加一个独立的作用域,并从HTML绑定变量

无论何时需要或不使用大括号,都取决于定义

 scope:{
    //Will interpret
    "this": "=",
    //Will interpret as a string
    "that": "@"
 }

 <my-directive this="interpretThis" that="{{interpretThat}}"></my-directive>
范围:{
//将解释
“this”:“=”,
//将解释为字符串
“该”:“@”
}
“that”将包含{{interpretatthat}}的字符串解释,而不是var

请注意,几乎所有的angular内置指令都使用“=”类型。因此,在99%的角度指令中,您不必使用大括号

希望有帮助。

在您的html中:

<div> This is some regular text your need {{interpretThis}} to say angular that you want to interpret that part </div>

//this is a regular attribute, angular don't know that he should interpret
<div class="{{interpretThis}}"></div>
这是一些常规文本,您需要{{interpretatthis}}来表示您想要解释该部分
//这是一个常规属性,我不知道他应该解释
关于指令:

当您定义一个指令时,您可以添加一个独立的作用域,并从HTML绑定变量

无论何时需要或不使用大括号,都取决于定义

 scope:{
    //Will interpret
    "this": "=",
    //Will interpret as a string
    "that": "@"
 }

 <my-directive this="interpretThis" that="{{interpretThat}}"></my-directive>
范围:{
//将解释
“this”:“=”,
//将解释为字符串
“该”:“@”
}
“that”将包含{{interpretatthat}}的字符串解释,而不是var

请注意,几乎所有的angular内置指令都使用“=”类型。因此,在99%的角度指令中,您不必使用大括号

希望有帮助。

在您的html中:

<div> This is some regular text your need {{interpretThis}} to say angular that you want to interpret that part </div>

//this is a regular attribute, angular don't know that he should interpret
<div class="{{interpretThis}}"></div>
这是一些常规文本,您需要{{interpretatthis}}来表示您想要解释该部分
//这是一个常规属性,我不知道他应该解释
关于指令:

当您定义一个指令时,您可以添加一个独立的作用域,并从HTML绑定变量

无论何时需要或不使用大括号,都取决于定义

 scope:{
    //Will interpret
    "this": "=",
    //Will interpret as a string
    "that": "@"
 }

 <my-directive this="interpretThis" that="{{interpretThat}}"></my-directive>
范围:{
//将解释
“this”:“=”,
//将解释为字符串
“该”:“@”
}
“that”将包含{{interpretatthat}}的字符串解释,而不是var

请注意,几乎所有的angular内置指令都使用“=”类型。因此,在99%的角度指令中,您不必使用大括号


希望能有所帮助。

基本上,只要你使用ng-,卷曲的东西就是html的。。。您不需要花括号,在控制器中的值是$scope.something change=“something=flase”和html-its{{somethin}

谢谢,但是为什么ng-src有花括号呢?