角度“数据”来自何处

时间:2015-06-07 16:50:25

标签: javascript angularjs

---在文件中给出此代码---

angular.module('storyCtrl', ['storyService'])

.controller('StoryController', function(Story, socketio) {

    var vm = this;

    Story.getStory()
        .success(function(data) {
            vm.stories = data;
        });

    vm.createStory = function() {
        vm.message = '';
        var newMessage = vm.storyData.content;
        var newStory = { str: newMessage , timeNow: new Date(), mess: "Hello" };
        Story.createStory(newStory)
            .success(function(data) {
                vm.storyData = '';

                vm.message = data.message;

            });
    };

    socketio.on('story', function(data) {
        vm.stories.push(data);
    })
})

“数据”在哪里初始化或者来自何处,因为它甚至不是全局变量或来自['storyService']。

谢谢

2 个答案:

答案 0 :(得分:1)

变量数据表示函数(getStory或createStory或on函数)返回给您在函数中使用的内容。例如,getStory函数可能返回一个json数组。在success函数中,此数据被分配给vm.stories变量。

这有帮助吗?

答案 1 :(得分:0)

<ol class="tc"> <li><strong>Preconditions</strong> <br/> <ol class="tc"> <li>Before we can provide you with Pay Monthly Services, you will need to:</li> <li>Complete our application process and provide us with any information which we reasonably ask for.</li> <li>Have a credit score and provide us with inancial security which is satisfactory to us.</li> <li>Provide us with valid proof of identity and evidence that you are permanently living in the Republic of Ireland.</li> <li>Provide us with valid proof that you are aged over 18 years.</li> </ol> </li> <li><strong>Tariff Limits</strong> <br/> <ol class="tc"> <li>Tariffs may include a limit on the volume of Services, including minutes, texts and/or internet access, which can be used without extra charge. Charges for all Services in excess of any Tariff limits will be charged at the rates set out in the charges.</li> </ol> </li> <li><strong>Call Charges covered by Tariff limits</strong> <br/> <ol class="tc"> <li>Tariff limits cover calls made in Ireland to: <ol class="alpha"> <li>standard Irish landlines; and</li> <li>08 numbers allocated to Irish mobile network operators.</li> </ol> </li> </ol>模块引用另一个名为storyCtrl的模块。稍微有些混乱,storyService模块包含一个名为storyService的服务(或工厂)。 Story服务提供了一种名为Story的方法。内部getStory 非常可能会使用getStory拨打电话。您可以告诉,因为$http不使用标准承诺,而是使用$http providesgetStorysuccess方法。