离子框架:$范围在简单的警告未定义 [英] Ionic Framework: $scope is undefined in simple alert

查看:119
本文介绍了离子框架:$范围在简单的警告未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.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>

这是我的code ...我不知道该如何解释,但它总是说未定义当我输入文本框的东西...

This is my code... I don't know how to explain but it always say undefined when I enter something on the text box...

但$ scope.goaltitle =东西正在对.controller(); ...

but $scope.goaltitle = "something" is working on the .controller(); ...

推荐答案

简答

这个问题的根源是,离子含量并创建一个继承中典型的孩子
  适用范围,这就是为什么 goaltitle 控制器范围的(基本型)比不同的您正在使用<$ C goaltitle $ C> NG-模型

The root cause of this issue is, ion-content does create a prototypically inherited child scope, that's why goaltitle(primitive type) of controller scope is different than the goaltitle you are using on ng-model

理想的做法是遵循点规则在定义视图模型。这样原型继承规则将随后得到与范围层次。

Ideally practice is to follow dot rule while defining view model. So that prototypal inheritance rule will get followed with scope hierarchy.

您应该定义对象,然后就分配所有的 NG-模型属性吧。

You should define object and then do assign all the ng-model property in it.

控制器

.controller('newGoalCtrl', function($scope, $ionicPopup) {
    $scope.model = {};
    $scope.addNewGoal = function() {
        alert($scope.model.goaltitle);
    };
});

然后让 goalTitle 目标,在里面等属性。

标记

<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>

我不希望再重新写完整的解释,所以在这里我引用 类似的答案 ,在那里我已经涵盖了所有的详细​​信息。

I don't want to re-write whole explanation again, so here I'm referencing similar answer, where I've covered all detailed information.

这篇关于离子框架:$范围在简单的警告未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆