javascript - 关于angularjs双向绑定的问题
本文介绍了javascript - 关于angularjs双向绑定的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我在html页面里定义了input的表签并且给定了一个ng-model="newLabel", 但为什么我在js里面用
$scope.newLabel获取不到值哦 一直是未定义。 js是外部引用的
这是控制器代码
app.controller('addLabelList',['$scope','severLabel',function ($scope,severLabel) {
console.log($scope.selectSite);
$scope.saveBtn = function () {
var str = $scope.newLabel;
console.log(str);
var _newLabel = {name: str, percent: "100% "};
console.log($scope.selectSite);
severLabel.setName(_newLabel);
}
}])
这是html代码
<ion-view view-title="添加标签" ng-controller="addLabelList">
<ion-nav-buttons side="left">
<a class="button button-icon icon ion-ios-undo-outline" href="#/tabs/label"></a>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-clear" style="font-size: 11pt;padding-right: 6px" ng-click="saveBtn()" ui-sref="tabs.label">
保存
</button>
</ion-nav-buttons>
<ion-content>
<ion-list type="list-inset " class="addLabel">
<ion-item>
标签名
<input type="text" placeholder="请输入标签" ng-model="newLabel" style="display: inline; padding-left: 20pt; font-size: 11pt">
</ion-item>
<ion-item class="item-select">
掌握情况
<select>
<option>10%</option>
<option>20%</option>
<option>40%</option>
<option>60%</option>
<option>80%</option>
<option selected="">100%</option>
</select>
</ion-item>
</ion-content>
</ion-view>
我每次在js中输出model时候都显示undefined
请问可能什么原因呢? 对了 我在别的地方试,将js写在html中可以获取到,但我现在必须要在外部引用呢
解决方案
我找到答案了,在这里https://segmentfault.com/q/1010000000666592 回答第一条
这篇关于javascript - 关于angularjs双向绑定的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文