Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.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 KnockoutJs';在AngularJs中的s_Javascript_Angularjs_Web_Knockout.js - Fatal编程技术网

Javascript KnockoutJs';在AngularJs中的s

Javascript KnockoutJs';在AngularJs中的s,javascript,angularjs,web,knockout.js,Javascript,Angularjs,Web,Knockout.js,我目前使用的AngularJs和我过去使用的KnockoutJs一样,我想使用类似于KnockoutJs的属性和属性,但似乎找不到我要找的东西。我的AngularJs$范围当前看起来像这样 $scope.data = { selectedCountry: ..., ... }; <div with="data.selectedCountry"> <div ng-bind="name"/> <div ng-bind="prop1"/>

我目前使用的AngularJs和我过去使用的KnockoutJs一样,我想使用类似于KnockoutJs的
属性和
属性,但似乎找不到我要找的东西。我的AngularJs$范围当前看起来像这样

$scope.data = {
    selectedCountry: ...,
    ...
};
<div with="data.selectedCountry">
  <div ng-bind="name"/>
  <div ng-bind="prop1"/>
  <div ng-bind="prop2"/>
<div>
现在selectedCountry是一个JS对象,在HTML中,我希望能够像这样做

$scope.data = {
    selectedCountry: ...,
    ...
};
<div with="data.selectedCountry">
  <div ng-bind="name"/>
  <div ng-bind="prop1"/>
  <div ng-bind="prop2"/>
<div>

而不是像我现在做的那样

<div>
  <div ng-bind="data.selectedCountry.name"/>
  <div ng-bind="data.selectedCountry.prop2"/>
  <div ng-bind="data.selectedCountry.prop3"/>
<div>


在AngularJs中有没有这样做的方法?任何帮助都将不胜感激。谢谢。

最接近这一点的是
ng init
指令

<div ng-init="c = data.selectedCountry">
    <div ng-bind="c.name"></div>
    <div ng-bind="c.prop1"></div>
    <div ng-bind="c.prop2"></div>
</div>


虽然它与Knockout(您不需要别名)不完全相同,但它应该会让您的生活更轻松,因为alias比编写完整的导航属性路径更好。

我已经搜索了很多。我发现没有什么比一个小把戏更好的了:

您可以通过以下方式模拟此功能:

<div ng-repeat="item in [data.selectedCountry]">
  <div ng-bind="name"/>
  <div ng-bind="prop2"/>
  <div ng-bind="prop3"/>
<div>


TG.

ngInit
与Knockout的
绝对不同。在您的示例中,您只是将一个新属性添加到范围中。Michael-同意。你对我的编辑太快了。我刚才在回答中提到了这一点但我认为这会帮助克雷格。@KrishnaTejaVeeramachaneni+1。我对你的代码做了一些编辑,把它删减到“最小”以表达观点。。。希望这是可以接受的@斯科特·里皮。绝对地谢谢。真正简短的回答是,没有与
相当的
。唯一接近的是
ngController