我在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代码
标签名
掌握情况
我每次在js中输出model时候都显示undefined
请问可能什么原因呢? 对了 我在别的地方试,将js写在html中可以获取到,但我现在必须要在外部引用呢
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我找到答案了,在这里https://segmentfault.com/q/1010000000666592 回答第一条
自身语法错误?少了<ion-list type="list-inset " class="addLabel">的关闭标签
console.log($scope.newLabel);
试下把数据绑定到一个对象上。比如用data.newLabel。
ng–click="saveBtn(newLabel)"