javascript – Ionic Framework:$scope在简单警报中未定义
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Ionic Framework:$scope在简单警报中未定义,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2046字,纯文字阅读大概需要3分钟。
内容图文
![javascript – Ionic Framework:$scope在简单警报中未定义](/upload/InfoBanner/zyjiaocheng/711/f464dfcd23dc4c8084485425896add6b.jpg)
.controller('newGoalCtrl', function($scope, $ionicPopup) {
$scope.addNewGoal = function() {
alert($scope.goaltitle);
};
});
<ion-pane view-title="goal">
<ion-header-bar class="bar-positive">
<div class="buttons">
<a nav-transition="android" class="button button-icon icon ion-arrow-left-b" ng-click="" href="#/index"></a>
</div>
<h1 class="title">Add New Goal</h1>
</ion-header-bar>
<ion-content class="padding" scroll="false" >
<div class="list">
<label class="item item-input">
<input type="text" placeholder="#Title" ng-model="goaltitle">
</label>
<label class="item item-input">
<span class="hashtag-title">#{{hashtagname}}</span>
</label>
<label class="item item-input">
<textarea placeholder="Goal"></textarea>
</label>
</div>
</ion-content>
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
<button class="button button-positive button-bar no-round-corner" ng-click="addNewGoal()">Add Goal</button>
</ion-tabs>
</ion-pane>
这是我的代码……我不知道如何解释但是当我在文本框中输入内容时它总是说未定义…
但$scope.goaltitle =“something”正在处理.controller(); …
解决方法:
简答
The root cause of this issue is,
ion-content
does create a prototypically inherited child
scope, that’s whygoaltitle
(primitive type) of controller scope is different than thegoaltitle
you are using onng-model
理想的做法是在定义视图模型时遵循点规则.因此,原型继承规则将遵循范围层次结构.
您应该定义对象,然后在其中分配所有ng-model属性.
调节器
.controller('newGoalCtrl', function($scope, $ionicPopup) {
$scope.model = {};
$scope.addNewGoal = function() {
alert($scope.model.goaltitle);
};
});
然后在其中有goalTitle,Goal等属性.
标记
<ion-content class="padding" scroll="false" >
<div class="list">
<label class="item item-input">
<input type="text" placeholder="#Title" ng-model="model.goaltitle">
</label>
<label class="item item-input">
<span class="hashtag-title">#{{hashtagname}}</span>
</label>
<label class="item item-input">
<textarea placeholder="Goal" ng-model="model.Goal"></textarea>
</label>
</div>
</ion-content>
我不想再重写整个解释,所以在这里我引用similar answer,其中我已经涵盖了所有详细信息.
内容总结
以上是互联网集市为您收集整理的javascript – Ionic Framework:$scope在简单警报中未定义全部内容,希望文章能够帮你解决javascript – Ionic Framework:$scope在简单警报中未定义所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。