该API参考范围页面说:
范围可以从父范围继承.
该开发者指南范围页说:
范围(原型)从其父范围继承属性.
那么,子范围是否始终从其父范围继承原型?有例外吗?当它继承时,它是否总是正常的JavaScript原型继承?
javascript inheritance prototype prototypal-inheritance angularjs
我目前正在使用以下内容.
$scope.$$childHead.customerForm[firstName], 以便:
<form name="customerForm">
<input type="text" name="firstName"
ng-model="data.customer.firstName"
tabindex="1"
ng-disabled="!data.editable"
validationcustomer />
</form>
Run Code Online (Sandbox Code Playgroud)
但这仅适用于Chrome.现在我尝试了以下内容:
$scope.editCustomerForm[firstName], 以便:
<form name="customerForm" ng-model="editCustomerForm">
<input type="text" name="firstName"
ng-model="data.customer.firstName" tabindex="1"
ng-disabled="!data.editable"
validationcustomer />
</form>
Run Code Online (Sandbox Code Playgroud)
哪个不起作用.请注意,我的表单位于Foundation选项卡中.我怎样才能访问firstName?
编辑:看起来它form没有被添加到scope基础选项卡中的时间.
任何人都有这个解决方案?
首先,最重要的是,plpler:http://plnkr.co/edit/v1uTz5
这是我遇到的问题的工作演示.
我有一个ng-include包括部分.
在部分内部我有一个带ngModelAND指令的文本输入.
模型在include中相应更新,但忽略了include之外的任何交互.{{test}}包含的外部不会更新,但{{test}}内部会更新.
该指令在被调用时处理该enter键并调用正确的范围和函数.但是,该$scope.test变量从未更新过,但$scope.testFinal已更新,ng-include模板会正确呈现.尝试重置$scope.test模型也不起作用.
我在这里错过了什么吗?或者这是指令的错误还是与ng-include?
我有以下主要观点
<div ng-include="'otions.html'"></div>
Run Code Online (Sandbox Code Playgroud)
和options.html有以下内容
<div ng-controller="OptionsController">Options</div>
<input type="text" ng-model="keyword" value="{{keyword}}" />
<button ng-click="search()">Search</button>
Run Code Online (Sandbox Code Playgroud)
但是"keyword"并未绑定到OptionsController中的范围.
app.controller('OptionsController',
['$scope', function($scope) {
$scope.keyword = "all";
$scope.search = function() {
console.log("hello")
};
}]);
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,我没有看到hello,关键字all没有出现在输入文本中.
我尝试按如下方式移动ng控制器部分
<div ng-controller="OptionsController" ng-include="'otions.html'"></div>
Run Code Online (Sandbox Code Playgroud)
事情按预期工作.
我仔细阅读了AngularJS中的答案- 在使用ng-include时失去了范围 - 我认为我的问题是相关的,但只需要更多的解释来解决正在发生的事情.
为了清理我的部分内容,我最近将一些全局菜单移动到单独的模板中,现在我将其包含在需要它们的视图中.由于菜单(包括搜索栏)是全局的,我创建了一个跟踪菜单状态等的服务.
在我开始包括之后,问题就变得有趣了.
视图的HTML(翡翠)
div(ng-controller='HeroUnitCtrl', ng-include src='heroTemplate')
div(ng-controller='MainSearchBarCtrl', ng-include src='searchBarTemplate')
div.row-fluid
div.span12
table.table.table-striped.table-bordered
tr
th
a(ng-click='setOrder("id")') ID#
th
a(ng-click='setOrder("client.name")') Kunde
th
a(ng-click='setOrder("technician.name")') Tekniker
th
a(ng-click='setOrder("createdAt")') Opprettet
th
a(ng-click='setOrder("statusString")') Status
tr(ng-repeat='record in records | orderBy:orderProp | filter:searchBar')
td
a(ng-href='#/records/show/{{record.id}}') {{record.id}}
td {{record.client.name}}
td {{record.technician.name}}
td {{record.createdAt}}
td {{record.statusString}}
Run Code Online (Sandbox Code Playgroud)
HTML(Jade)searchBarTemplate
input#searchField.input-xxlarge(type='text', placeholder='placeholder', ng-change='searchBarUpdated()', ng-model='searchBar')
Run Code Online (Sandbox Code Playgroud)
现在到了我真的不明白,
MainSearchBarCtrl
function MainSearchBarCtrl(MainSearchBarService, $scope, $location) {
$scope.searchBarTemplate = 'partials/main-searchbar';
$scope.searchBar = 'Hello World!';
$scope.searchBarUpdated = function() {
console.log('Search bar update: ' + $scope.searchBar);
MainSearchBarService.searchBarUpdated($scope.searchBar);
}
}
Run Code Online (Sandbox Code Playgroud)
最初,searchBar …